Refactored user authentication