Refactor user authentication