backend login refactoring