Recover forgot password using passwordrecovery control in asp.net

In this article I will explain how to reset or recover forgot password using password recovery control in asp.net membership.

In many websites we will see option like forgot password this will help us to recover forgot password of users. If we click on forgot password option then they will take username or email after that they will check those details in database if those are exists then they will send new password details to our email.

To implement this one we need to write much code if we use asp.net membership concept we can achieve this functionality just by using passwordrecovery control.

The PasswordRecovery control consists of three views:

  1. UserName – In First view user needs to enter correct username. If username exists in membership then it will display another option i.e. Question and answer otherwise it will throw error like we are unable to access your information

  2. Question and Answer – After Username validated then it will ask for security question and answer. This Question and answer optional if we don’t want we can remove by setting some properties in web.config. If we remove these options passwordrecovery control will send mail after successful validation of username. To remove Question and Answer option we need to set option requiresQuestionAndAnswer="false" in web.config.
  3. Success – After successful validation of security questions and answer it displays a message informing to user that his password has been emailed.

Passwordrecovery control will reset existing password and it will send new password to our email.


After successful verification of username, password we need to send mail for that we need to add smtp server hostname, port address in web.config section using in configuration section. 


<configuration>
<system .net="">
<mailsettings>
<smtp deliverymethod="Network" from="satasiyanikunj444@gmail.com">
<network host="100.33.1.1" port="25">
</network></smtp>
</mailsettings>
</system>
</configuration>

Now open your aspx drag and drop PasswordRecovery control from Login Controls section after that our page code will be like this

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Forgot Password in asp.net membership</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:passwordrecovery id="Passwordrecovery1" runat="server"> </asp:passwordrecovery>
</div>
</form>
</body>
</html>


Here don’t forgot to set database connection and smtp settings in web.config

First set the connectionstring and smtp settings in configuration section like this

<connectionstrings>
<add connectionstring="Data Source=NikunjSatasiya;Initial Catalog=AspMembership;Integrated Security=true" name="dbconnection" providername="System.Data.SqlClient">
</add></connectionstrings>
<system .net="">
<mailsettings>
<smtp deliverymethod="Network" from="satasaiyanikunj444@gmail.com">
<network host="100.33.1.1" port="25">
</network></smtp>
</mailsettings>
</system>

After that write the following code in system.web section

<membership>
<providers>
<clear>
<add applicationname="SampleApplication" connectionstringname="dbconnection" name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider">
</add></clear></providers>
</membership>
<profile>
<providers>
<clear>
<add applicationname="SampleApplication" connectionstringname="dbconnection" name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider">
</add></clear></providers>
</profile>
<rolemanager enabled="true">
<providers>
<clear>
<add applicationname="SampleApplication" connectionstringname="dbconnection" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider">
</add></clear></providers>
</rolemanager>


DEMO OUTPUT :

Previous
Next Post »
Thanks for your comment