Refactor login authentication