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

Change user password using changepassword control in asp.net membership provider

Jan 8, 2012
Introduction:

In this article I will explain
how to use changepassword control to change password in asp.net membership provider.

Description:

In previous posts I explained clearly how to create users using createuserwizard or programmatically create users using asp.net membership and I explained  how to get forgot password through email. In previous post Get forgot password through mail it will reset our password and sent randomly generated new password through mail. It’s very hard to remember randomly generated password. If we allow users to change their passwords directly that is very convenient. We can achieve this one easily by using changepassword control asp.net membership. 

changepassword control allows currently logged in users to change their password. If we want to change another user password then it’s not possible because every time it will take only currently logged in user. 

If we want change password for other users we need to set property DisplayUserName= "True" in changepassword control (right click on changepassword >> change DisplayUserName="True"). It will add other control UserName in changepassword before set DisplayUserName property it contains only 3 controls those are old password, new password, confirm new password.

Now open your aspx drag and drop changePassword 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>Change Password</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ChangePassword ID="ChangePassword1" runat="server" DisplayUserName="True">
</asp:ChangePassword>
</div>
</form>
</body>
</html>
Here don’t forgot to set database connection settings in web.config 

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>
Now run your application and enter username, old password and new password after successful change of password we will get success message.

Demo


If you want send mail after successful change of password we need to set the smtp server configurations (<system.net>) in web.config file of configuration section. If you don’t know how to set then check this post Recover forgot password in asp.net
 

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

12 comments :

Nazmul Hossain said...
This comment has been removed by the author.
Anonymous said...

Thanks

saikumar... said...

Nice Post Brother.............keep on going

Anonymous said...

How do i make it work with my custom database structure?

Anonymous said...

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: The configuration section cannot contain a CDATA or text element.

Source Error:

Line 50:
Line 51: "/>
Line 53:
Line 54:

Anonymous said...

Hello Sir,

I liked your article. But i have to do the same but without using membership. can you please explain me how to do this or give some related article?

birkin said...

Hi, this is a useful expert issue.

Anonymous said...

Nice post

Unknown said...

where is system.web section in asp.net

Anonymous said...

Hi suresh,

I want to change password by using table in my Data...Please tell me how can i ?

Anonymous said...

how to handle the Password incorrect or New Password invalid. New Password length minimum: 6. Non-alphanumeric characters required: 0. in javscript sir

Anonymous said...

how to create a rdlc report where 100 columns depending on user selection need to show in report

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 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.