Login method and refactoring