In this article we will see how to reset the password through the forgot password page in MVC. Add an Action link on login page if the user forgets his/her password.The link redirects the user to the below page from where the user can get a reset link on the registered email id.
In this article we will see how to reset the password through forgot password page in MVC.
Add an Action link on login page if the user forgets his/her password.The link redirects the user to the below page from where the user can get a reset link on the registered email id.
Note: The user should be a already-registered user.
This is how the forgot password page looks .The user needs to enter the registered and valid email id on which the reset link will be sent.
Below is the code of the forgot password action method
In this article we are using gmail for sending the reset link which requires some settings on the web.config file (the settings are given below the methods).The below method is used to fetch those settings from the web.config file
Web config settings
The above code will send a reset link on the registered email.Once the mail is received the user needs to click on the reset link which will redirect the user to the reset password page.
The mail will look like the below image,
Your changed password
Please find the Password Reset Link.
http://localhost:****/Account/ResetPassword?email=**************.com&code=UNbRRYVXWO4mqC15Gfdpaw2
On clicking the above link you will be redirected to a reset password page with the return/ reset token.The return/reset token is attached with the url of the reset password page and hepls in replacing the old password with the new one.User needs to enter the new password in the below page to reset it.
The code for Resetting password is as below:
The Return token in WebSecurity in Mvc hepls in replacing the old password with the new one.The ResetPassword() method in websecurity is used to reset the password with the help of return token of the registered user.
ASP.NET MVC 5: A Beginner’s Guide