The PasswordRecovery control available in ASP.NET 3.5 assists is a part of Login controls and helps to recover their password who have forgotten their passwords. It enables a user to request an e-mail message containing either a new password or the password already associated with his or her user name or email.
PasswordRecovery Templates The PasswordRecovery control supports templates for every view. The PasswordRecovery control displays the Question view only when the membership provider defined in the MembershipProvider property supports password question and answer. The following code snippet shows how to use a PasswordRecovery control in an ASP.NET page.
We need to configure the email setup including email from, subject, and SMTP server in Web.config. Here is the SMTP setup settings. Rest everything is taken care by the control itself. <MailDefinition From="[email protected]" Subject="Forgetton Password" Priority="High"> Download the attached project for more details.
The PasswordRecovery Web control uses Internet e-mail services to send recovered or new passwords to users. There are inherent security risks with sending passwords in e-mail. You should determine whether these security risks are acceptable to your site.
Users can recover passwords only when the membership provider defined in the MembershipProvider property supports clear text or encrypted passwords. Because hashed passwords cannot be recovered, users at sites that use hashed passwords can only reset their passwords.
The PasswordRecovery control can be used when a membership user has not been approved (MembershipUser.::.IsApproved is set to false), but it cannot be used when a membership user has been locked out (MembershipUser..::.IsLockedOut is set to true).
The e-mail message is sent using the MailDefinition class. To be able to send e-mail to users, you must configure a mail server in your application's Web.config file. You can change the content of the e-mail sent to users by setting a custom message in the MailDefinition property.
It is not possible to guarantee that a user will receive or view an e-mail message. To verify that a user has received a notification by e-mail, consider providing a confirmation link in the message, allowing the user to confirm that the notification was received.
The PasswordRecovery control has three states, or views:
The following table lists each style property of the PasswordRecovery control and indicates which view it affects.
PasswordRecovery Control Events
BorderColor="#E6E2D8" BorderPadding="4" BorderStyle="Solid" BorderWidth="1px"
Font-Names="Verdana" Font-Size="Large"
onsendingmail="PasswordRecovery1_SendingMail" Width="532px" >
<MailDefinition From="[email protected]" Subject="Forgetton Password" Priority="High">
</MailDefinition>
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<SuccessTextStyle Font-Bold="True" ForeColor="#5D7B9D" />
<TextBoxStyle Font-Size=Medium />
<UserNameTemplate>
<span style="text-align:center">
<font face="Verdana">
<h3>Forgot Password </h3>
UserName: <asp:TextBox ID="UserName" runat="server"
Width="236px"></asp:TextBox> <asp:Button ID="SubmitButton" runat="server"
Text="SEND" CommandName="Submit" /><br />
<span style="color: #FF0000">
<asp:Literal ID="FailureText" runat="server"></asp:Literal>
</span>
</font>
</span>
</UserNameTemplate>
<QuestionTemplate>
<h2>Forgot Password</h2>
Hello <asp:Literal ID="UserName" runat="server"></asp:Literal><br />
Please answer your password question : <br />
<asp:Literal ID="Question" runat="server"></asp:Literal>
<asp:TextBox ID="Answer" runat="server"></asp:TextBox><br />
<asp:Button ID="SubmitButton" runat="server" Text="Send Answer By Mail"
CommandName="Submit"/><br />
<asp:Literal ID="FailureText" runat="server"></asp:Literal>
</QuestionTemplate>
<SuccessTemplate>
Your password has been sent to your email addres
<asp:Label ID="EmailLabel" runat="server"></asp:Label>
</SuccessTemplate>
<TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.9em"
ForeColor="White" />
<SubmitButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em"
ForeColor="#284775" />
</asp:PasswordRecovery>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network host="localhost" port="25" />
</smtp>
</mailSettings>
</system.net>
</MailDefinition>

sajjad khanPosted Jun 10, 2012, 2:24 AM
Hi , I want Email Template instead of UserName template (i.e i want to check using email rather username) Can u Tell me
Raghavanand VBVPosted May 28, 2012, 6:49 AM
thanks for the help
Praveen RawatPosted Jun 1, 2011, 12:44 PM
really very helpfull....thanx a lot....
Mukesh RajaramPosted Apr 29, 2011, 8:13 AM
please send the forget password help by email id
snail pacePosted Jan 14, 2009, 3:01 PM
Good example, although my question is a bit different not involving password recovery. A user enters their email address to a webform in ASP.NET 3.5 and then the application adds it to the SQL table. "Now, the next step is an email must be sent to the user with a link, so that when they visit that link, it is a confirmation that they are the correct user. How to get the application to do this and also everytime a payment is due for the user a reminder email must be sent out automatically to the user." My question is the area in quotes. Thanks