refactoring login method