Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies


Introduction:

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

Description:

In previous post I explained clearly about create users using CreateUserWizard in asp.net membership or programmatically insert user details in membership and create or removes roles in asp.net membership and Assign roles to users .Now I will explain how to get forgot password using passwordrecovery control. 

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:

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”

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. Check this post to set properties remove Question and answer options 

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  <system.net> in configuration section.

<configuration>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="administrator@aspdotnet-suresh.com">
<network host="100.33.1.1" port="25"/>
</smtp>
</mailSettings>
</system.net>
</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 name="dbconnection" connectionString="Data Source=SureshDasari;Initial Catalog=AspMembership;Integrated Security=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="administrator@aspdotnet-suresh.com">
<network host="100.33.1.1" port="25"/>
</smtp>
</mailSettings>
After that write the following code in system.web section

<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="dbconnection" applicationName="SampleApplication"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="dbconnection" applicationName="SampleApplication"/>
</providers>
</profile>
<roleManager enabled="true">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="dbconnection" applicationName="SampleApplication"/>
</providers>
</roleManager>
Demo

Enter valid username, Question and answer you will get email with new password like this 


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

43 comments :

Mehtab Ali said...

Its good work for the beginners..keep it up suresh..

Anonymous said...

how to configure asp.net smtp??? i mean how to know the smtp server name& port number???plz reply need help

Anonymous said...

gud

Anonymous said...

Hi suresh i have tried this one but it is giving me an error when i have clicked the submit button of pwd recovery control as below and i m using sql server2008 and visual studio2008:

Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.

Anonymous said...

very very thanks

suresh gupta said...

Sir plz help me i tried as per your instruction but i am getting this error:
Mailbox unavailable. The server response was: 5.7.1 Unable to relay for suresh.gupta405@gmail.com
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for suresh.gupta405@gmail.com

Suresh Dasari said...

@Comment 4....
i hope that problem because of you didn't install asp.net membership database in your sql server. please install it based on this post http://www.aspdotnet-suresh.com/2011/01/how-to-use-custom-database-for-aspnet.html

Suresh Dasari said...

@suresh gupta....
that problem is because of your smtp server. Please check your smtp server connection correct or not.

suresh gupta said...

sir in above code what will be application name in my case.i mean what is applicationName?

Suresh Dasari said...

@suresh gupta..
applicationName means your project name

suresh gupta said...

hie there, i want to be able to pass multiple parameters
to another page. currently, i am able to do so, but
somehow i feel it is not the correct way to do it. below
is part of what i have so far.

'first page
Private Sub btnOK_ServerClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnOK.Click
Response.Redirect("InputValues.aspx?Requestor=" &
txtRequestor.Text & " Lower= " & txtLower.Text)
End Sub

'second page
Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim strRequestor As String
strRequestor = Request.QueryString("Requestor")
Response.Write("Requestor = " & strRequestor)
End Sub

the output i will get is :
Requestor = * Lower = 10

My question is, how can i pass the 2nd parameter(in the
txtLower.Text) to the next page without passing the
keyword "Lower" and still obtain the same output?

i want my second page to look like this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim strRequestor As String
Dim strLower As String
strRequestor = Request.QueryString("Requestor")
Response.Write("Requestor = " & strRequestor)
Response.Write("
")
strLower = Request.QueryString("Lower")
Response.Write(strLower)
End Sub

Please help, and thanx in advance.

Datta Kawade said...

I am creating same application as per your code but i cant able to get password....will u pls help me...

Anonymous said...

No connection could be made because the target machine actively refused it 100.33.1.1:20
i get this error... can you help me out?

Anonymous said...

No connection could be made because the target machine actively refused it 100.33.1.1:20
i get this error... can you help me out?

i got the same error but i used port 25

Asha said...

hi Suresh i tried with the code but, When i enter the Username and click on the submit button error like this
We were unable to access your information. Please try again. i have set up the sql connection.

poonam said...

hi i tried this code for forgot password recovery but it gives me error Unrecognized configuration section configuration as i have changed network host value to localhost. can please tell me correct value.

chetan said...

hello sir, this article works fine. but finally i got only one error, that is i got confirmation that
password sent to your email. but actually i have not receiving that mail to my email id. why so ? thanks.
pls send me solution to this id chetan10j@gmail.com

rifayee said...

hi suresh,i have read all the articles regarding crystal reports,and i tried to my project its working..but i developing one webapplication,in that application i am using a grid view in one aspx page,in that grid view i have displayed all the database fields,and i provide a option like edit,delete,update,print,view in that grid view.my question is when i click the print option the particular or selected row will be print in the crystal report,but i wont work,,do u have any idea or articles for displaying particular report ,,,thanks

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
dilip mishra said...

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. pl10sm15290604pbc.1 - gsmtp

hermes said...

I've read the entire article,but the forget password problem is still exist.

gupta gs said...

hai your demonstration is nice but is works in windows7,if so please mail the process to configure password recovery control.Thank you

shashi ranjan said...

Hii..

Your demonstration is very useful to me.
Can you please help me out,if i want to recover the password and send it to on registered mobile no.
Please provide me if there is any solution.

Thanks...keep it up

Anonymous said...

change password program:
1.we can create table called Login
releated stored procedure sp_Login
2.we can create storedprocedure called sp_changepasword it depends on Login table
protected void Button1_Click(object sender, EventArgs e)
{
cmd = new SqlCommand();
cmd.CommandText = "sp_PasswordChange";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", TextBox1.Text);
cmd.Parameters.AddWithValue("@Password",TextBox2.Text);
cmd.Parameters.AddWithValue("@newpassword", TextBox3.Text);
int icount = dobj.ExecuteNonQuery(cmd);
if (icount > 0)
{
lblmsg.Text = "your password Update sucussfully..!";
}
else
{
lblmsg.Text = "Please check your current password!";
}



}

Anonymous said...

I want to set for some particular pages like, after logout it redirects to home page & then from this home page I want to disable the back button. Please help me.

Prasanta Kumar Giri said...

I want to set for some particular pages like, after logout it redirects to home page & then from this home page I want to disable the back button. Please help me.

Dhayanithivijayan said...

your post was good,but when i tried pasword recovery control i got error like
"No connection could be made because the target machine actively refused it 127.0.0.1:25"
even i installed asp.net membership database in my sql server.
Please reply me as soon as possible.

Ashvin said...

How should i redirect from login page to password recovery page if user enter max. invalid password attempt?

Anonymous said...

Hi Suresh,

How 2 configure SMTP in my System , i am using windows 7 o/s , how the smtp configuration setttings should be done in my System



Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.