refactored login and linked authenticateUser