Refactor forgotpassword functionality.