Fixed wrong redirect after login and potential security issues