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.
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. |
|||
|
|||
12 comments :
Thanks
Nice Post Brother.............keep on going
How do i make it work with my custom database structure?
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:
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?
Hi, this is a useful expert issue.
Nice post
where is system.web section in asp.net
Hi suresh,
I want to change password by using table in my Data...Please tell me how can i ?
how to handle the Password incorrect or New Password invalid. New Password length minimum: 6. Non-alphanumeric characters required: 0. in javscript sir
how to create a rdlc report where 100 columns depending on user selection need to show in report
Note: Only a member of this blog may post a comment.