refactored authenticate user