Build a Change Password Feature for ASP .Net Websites

If you run an ASP.NET website using webforms combined with member access, you can easily add a Change Password feature by utilizing built-in controls. This works well on Umbraco websites using Public Access.

How to Change ASP .NET Passwords

This article focuses on implementation using Webforms. In a future article, I will discuss how this class can be applied to sites running MVC/Razor.

What does the ChangePassword class do?

This class allows you to offer users the ability to change their password once they have logged in. This is useful if a password needs to be changed for security purposes or perhaps just a personal preference. This class is different from the PasswordRecovery class which I discussed in a previous article.

Build a Change Password Feature for ASP .Net Websites

Tweet this

Getting started using the ChangePassword class

First off, the page running this control does not need to be behind a secured section/folder. This differs from the PasswordRecovery class which should always be outside a secured section/folder for obvious reasons.

The first thing you will want to do is create a new page template to run the control. Implementation is quite easy, just add the following code to your page wherever you want the form to appear. Below is the most basic implementation.

<form runat="server">
   <asp:ChangePassword ID="ChangePassword1" runat="server"></asp:ChangePassword>

This will generate a headline followed by a three input fields, and a submit button with the following labels:

  • Current Password
  • New Password
  • Confirm Password

When submitted, the page is reloaded with either a success or failure message based on your input. The user is NOT logged out at this point. If successful, the new password is stored and hashed.

I prefer however that the user is logged out upon successful submission and that user be returned to the login page. This is easily achieved by modifying the parameters as follows.

<form runat="server">
   <asp:ChangePassword ID="ChangePassword1" SuccessPageUrl="/login/" OnChangedPassword="LoginStatus1_LoggedOut" runat="server"></asp:ChangePassword>

The OnChangePassword parameter is an event handler that is fired upon a successful submission. The following event handler code should also appear in the HTML of the change password page.

<script runat="server">
protected void LoginStatus1_LoggedOut(object sender, EventArgs e)

The SuccessPageUrl parameter returns the member to the login page. Modify this value to accommodate your site structure.

Additional ChangePassword class parameters

There are dozens of additional parameters that can be added to this control. You can control or override field labels, assign classes for styling and much more. For a complete list of all parameters and code examples, visit the ChangePassword MSDN page.

Robert Valcourt
Oct 28, 2016
By Robert Valcourt

Get Email Updates (It's FREE)

Zero Spam. Unsubscribe Anytime. We respect your privacy!

Made With In Whistler