Compartilhar via


ChangePassword Web Server Control Declarative Syntax 

Creates a user interface that enables users to change their Web site password.

<asp:ChangePassword
    AccessKey="string"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderPadding="integer"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    CancelButtonImageUrl="uri"
    CancelButtonText="string"
    CancelButtonType="Button|Image|Link"
    CancelDestinationPageUrl="uri"
    ChangePasswordButtonImageUrl="uri"
    ChangePasswordButtonText="string"
    ChangePasswordButtonType="Button|Image|Link"
    ChangePasswordFailureText="string"
    ChangePasswordTitleText="string"
    ConfirmNewPasswordLabelText="string"
    ConfirmPasswordCompareErrorMessage="string"
    ConfirmPasswordRequiredErrorMessage="string"
    ContinueButtonImageUrl="uri"
    ContinueButtonText="string"
    ContinueButtonType="Button|Image|Link"
    ContinueDestinationPageUrl="uri"
    CreateUserIconUrl="uri"
    CreateUserText="string"
    CreateUserUrl="uri"
    CssClass="string"
    DisplayUserName="True|False"
    EditProfileIconUrl="uri"
    EditProfileText="string"
    EditProfileUrl="uri"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
                Large|X-Large|XX-Large"
        Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    Height="size"
    HelpPageIconUrl="uri"
    HelpPageText="string"
    HelpPageUrl="uri"
    ID="string"
    InstructionText="string"
    MailDefinition-BodyFileName="uri"
    MailDefinition-CC="string"
    MailDefinition-From="string"
    MailDefinition-IsBodyHtml="True|False"
    MailDefinition-Priority="Normal|Low|High"
    MailDefinition-Subject="string"
    MembershipProvider="string"
    NewPasswordLabelText="string"
    NewPasswordRegularExpression="string"
    NewPasswordRegularExpressionErrorMessage="string"
    NewPasswordRequiredErrorMessage="string"
    OnCancelButtonClick="CancelButtonClick event handler"
    OnChangedPassword="ChangedPassword event handler"
    OnChangePasswordError="ChangePasswordError event handler"
    OnChangingPassword="ChangingPassword event handler"
    OnContinueButtonClick="ContinueButtonClick event handler"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnSendingMail="SendingMail event handler"
    OnSendMailError="SendMailError event handler"
    OnUnload="Unload event handler"
    PasswordHintText="string"
    PasswordLabelText="string"
    PasswordRecoveryIconUrl="uri"
    PasswordRecoveryText="string"
    PasswordRecoveryUrl="uri"
    PasswordRequiredErrorMessage="string"
    runat="server"
    SkinID="string"
    Style="string"
    SuccessPageUrl="uri"
    SuccessText="string"
    SuccessTitleText="string"
    TabIndex="integer"
    ToolTip="string"
    UserName="string"
    UserNameLabelText="string"
    UserNameRequiredErrorMessage="string"
    Visible="True|False"
    Width="size"
>
        <CancelButtonStyle/>
        <ChangePasswordButtonStyle/>
        <ChangePasswordTemplate>
            <!-- child controls -->
        </ChangePasswordTemplate>
        <ContinueButtonStyle/>
        <FailureTextStyle/>
        <HyperLinkStyle/>
        <InstructionTextStyle/>
        <LabelStyle/>
        <MailDefinition
            BodyFileName="uri"
            CC="string"
            From="string"
            IsBodyHtml="True|False"
            Priority="Normal|Low|High"
            Subject="string"
>
                <EmbeddedObjects>
                        <asp:EmbeddedMailObject
                            Name="string"
                            Path="uri"
                        />
                </EmbeddedObjects>
        </MailDefinition>
        <PasswordHintStyle/>
        <SuccessTemplate>
            <!-- child controls -->
        </SuccessTemplate>
        <SuccessTextStyle/>
        <TextBoxStyle/>
        <TitleTextStyle/>
        <ValidatorTextStyle/>
</asp:ChangePassword>

Remarks

Use the ChangePassword control on a page to enable your Web site users to change the passwords that they use to log on to your Web site.

Security noteSecurity Note

Transmitting passwords over HTTP is a potential security vulnerability. HTTP transmissions can be viewed or compromised by malicious users. To improve security when using login controls, you should use the HTTPS protocol with secure sockets layer (SSL) encryption to ensure that the user's password cannot be read during postback. For more information, see Securing Login Controls.

The ChangePassword control uses the membership provider that is defined in the MembershipProvider property to change the password that is stored in the membership provider data store for the Web site. If you do not assign a membership provider, the ChangePassword control uses the default membership provider that is defined in the membership section of the Web.config file.

For more information on using the ChangePassword control and other ASP.NET login controls, see Login ASP.NET Controls.

Example

The following code example shows how to set the NewPasswordRegularExpression property to define a regular expression that checks passwords to ensure that they meet the following criteria:

  • Are greater than six characters.

  • Contain at least one digit.

  • Contain at least one special (non-alphanumeric) character.

The password requirements that are contained in the PasswordHintText property are displayed to the user.

If the password that is entered by the user does not meet the requirements of the NewPasswordRegularExpression property, the text that is contained in the NewPasswordRegularExpressionErrorMessage property is displayed to the user. If a new password is not entered, the text that is contained in the NewPasswordRequiredErrorMessage property is displayed to the user.

NoteNote

The new password must meet the minimum requirements that are set by the membership provider in the MinRequiredPasswordLength, MinRequiredNonAlphanumericCharacters, and PasswordStrengthRegularExpression properties. If the password does not meet these requirements, the ChangePasswordError event is raised.

<%@ page language="VB"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>Change Password with Validation</title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <asp:changepassword id="ChangePassword1" runat="server"
  PasswordHintText = "Please enter a password at least 7 characters long, containing a number and one special character."
  NewPasswordRegularExpression = '@\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})' 
  NewPasswordRegularExpressionErrorMessage = "Your password must be at least 7 characters long, and contain at least one number and one special character.">
  </asp:changepassword>
  </div>
  </form>
</body>
</html>
<%@ page language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>Change Password with Validation</title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <asp:changepassword id="ChangePassword1" runat="server"
  PasswordHintText = 
    "Please enter a password at least 7 characters long, 
    containing a number and one special character."
  NewPasswordRegularExpression =
    '@\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})' 
  NewPasswordRegularExpressionErrorMessage =
    "Error: Your password must be at least 7 characters long, 
    and contain at least one number and one special character." >
  </asp:changepassword>
  </div>
  </form>
</body>
</html>

See Also

Reference

ChangePassword

Other Resources

Login ASP.NET Controls