Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

ASP.NET 2.0 Quickstart Tutorials


The ChangePassword control provides the functionality to confirm a user�s existing password prior to executing the password change. In the case where the user is not already authenticated on the web site, their identity is confirmed and their password changed but they are not automatically logged into the website. Since the user has entered the new password, there is no requirement to send that new password in email, however the control supports the option to send the user a confirmation email.

Security Note: It may be possible for the email containing the user�s password to be intercepted by hackers and thus compromise the user�s account. The ChangePassword control uses the Membership service to retrieve or reset the user�s password. The default Membership provider from your configuration file will be used automatically, however you can also set the Membership provider as a property on the control. The ChangePassword control consists of two discrete views which are displayed to the user sequentially. The ChangePassword view is the first view shown to the user and it collects processes the current password, new password, confirmation of new password and optionally the username (this is required if the user is not currently authenticated). The Success view is an optional view that is displayed when the password has been successfully changed. In addition to the success view the control supports redirecting the user to new page if they are successful instead of displaying the success view. Key elements of the ChangePassword Control are:
  • Username Label and Textbox: Collects the string used to identify the user in the membership system. If not displayed in the control the current user�s identity will be used, if the user is not authenticated the attempt to change the password will always fail.
  • Password label and Textbox: Collects the user current password.
  • New Password label and Textbox: Collects the new password the user would like to set.
  • Confirm New Password label and Textbox: Uses a compare validator to confirm that this entry and the new password value are the same. Note: If the control is templated and the compare validator is removed, this comparison is not done and the value of the new password textbox is always sent to the membership service.
  • ChangePasswordButton: The button that initiates changing the password.
  • SuccessText : Text displayed when the password has been successfully reset.
  • Title (ChangePassword and Success views) and Instruction (ChangePassword view): Text to orient and guide the user through the process.
  • Links: Configurable link to Help, CreateUser, PasswordRecovery and Profile information.
  • Validators: Required field validators, and a compare validator for the new password and confirm new password textboxes.
In addition to the visual elements displayed to the user on the web site, the ChangePassword control also contains a MailDefintion that determines the content of the email that is sent to the user. The ChangePassword control does not contains a default email message but you can add your own text or html file to be used as the body of the message. If you are creating your own email file the control will automatically insert the user�s username and password for the following strings: < %UserName%> <%Password%> in the designated email file.

Simple ChangePassword Sample

This sample demonstrates the basic ChangePassword functionality when a user is already authenticated on the website.

VB ChangePassword
Run Sample View Source

ChangePassword Behaviors

There are a variety of ways to customize the ChangePassword control to meet your needs. Some of the means of customization are:
  • UserName: Change the mail message that is sent to your users with their retrieved or reset password.
  • PasswordHint: Provides text relative to the new password textbox to help users pick a secure and valid password. For example, must be 7 characters and contain 1 non-alphabetic character.
  • SuccessPageUrl: Determines what web page a user will be redirected to when their password is successfully changed. If there is a SuccessPasswordUrl, the user will not be shown the Success view of the control.
  • CancelDestinationPageUrl: Determines the web page that a user will be shown when they click on the Cancel button.
  • ContinueDestinationPageUrl: Determines the web page that a user will be shown if they click on the Continue button.
  • Links: Displaying icons and links to other information and tasks.

ChangePassword Behaviors Sample

This sample demonstrates how to set a CancelDestinationPageUrl and ContinueDestinationPageUrl. This sample also enables non-authenticated users to change their password after verifying their current password. You will also notice that the optional Help and Profile links are displayed within the control.

VB ChangePassword Behaviors
Run Sample View Source

ChangePassword Styles

The ChangePassword control supports customizing the look of the control through a series of style properties that control different parts of the control.
  • Control Style: Applies to all sections of the ChangePassword control and is merged with other styles set on the control.
  • Label Style: Applies to the username and different password labels.
  • TextboxStyle: Applies to the textboxes.
  • TitleTextStyle: Applies to the title text on both views.
  • SuccessTextStyle: Applies to the text on the success views.
  • InstructionTextStyle: Applies to the instruction text.
  • PasswordHintStyle: Applies to the password hint text.
  • HyperlinkStyle: Applies to all of the links link.
  • ChangePasswordButtonStyle: Applies to the ChangePassword button.
  • ContinueButtonStyle: Applies to the Continue button.
  • CancelButtonStyle: Applies to the Cancel button.
  • FailureTextStyle: Applies to the text returned if the membership system fails to reset or retrieve the password.
  • ValidatorTextStyle: Applies to the text displayed if the required field valuators fail.

ChangePassword Styles Sample

This sample demonstrates various style properties on the control. This sample also enables non-authenticated users to change their password after verifying their current password. This is particularly useful in systems that allow a user to have several screen accounts.

VB ChangePassword Styles
Run Sample View Source

ChangePassword Templates

The ChangePassword control is a composite control which unites child controls (e.g. textboxes, buttons) and additional logic (calling Membership, handling errors) to implement the ChangePassword functionality. For even more control over the display of the ChangePassword control you can template the control. To ensure that the ChangePassword control continues to function when it is templated, your control must use well known control IDs or command names for some of the child controls. In addition to the key controls required for functionality (e.g. textboxes) additional controls with well known IDs are supported and will be automatically hooked up to the ChangePassword functionality. Here is a list of control IDs and command names that are used in template editing mode:
  • ID=UserName
  • ID=CurrentPassword
  • ID=NewPassword
  • ID=ConfirmNewPassword
  • ID=FailureText
  • CommandName=ChangePassword This control can have any control ID but must support command bubbling.
  • CommandName=Continue This control can have any control ID but must support command bubbling.
  • CommandName=Cancel This control can have any control ID but must support command bubbling.
You can also add additional functionality to the ChangePassword control through templating. For example, you can collect additional information from the user by adding additional controls to the template or by adding additional client side validation of the textboxes.

ChangePassword FindControl Template Sample

This sample demonstrates a basic templated ChangePassword (no fancy styles) to show the correct control IDs and command names for key features of the ChangePassword control as well as how to programmatically find a control inside a template. Be sure to choose an account type when you are changing your password.

VB ChangePassword Templates
Run Sample View Source