Refactor verify login function