ChangePassword Web 服务器控件声明性语法

更新:2007 年 11 月

创建一个用户界面,使用户可以更改其网站密码。

<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>

备注

在页上使用 ChangePassword 控件可以使网站用户更改他们用于登录到网站的密码。

安全说明:

通过 HTTP 传输密码存在潜在的安全漏洞。恶意用户可能会查看或破坏 HTTP 传输内容。若要在使用登录控件时提高安全性,应使用带有安全套接字层 (SSL) 加密的 HTTPS 协议来确保用户密码在回发期间不会被读取。有关更多信息,请参见保证登录控件的安全

ChangePassword 控件使用 MembershipProvider 属性中定义的成员资格提供程序更改密码,该密码存储在网站的成员资格提供程序数据存储区中。如果未分配成员资格提供程序,则 ChangePassword 控件使用 Web.config 文件的 membership 节中定义的默认成员资格提供程序。

有关使用 ChangePassword 控件和其他 ASP.NET 登录控件的更多信息,请参见 ASP.NET 登录控件概述

示例

下面的代码示例说明如何设置 NewPasswordRegularExpression 属性来定义一个正则表达式,用于检查密码以确保它们满足下列条件:

  • 多于 6 个字符。

  • 至少包含一个数字。

  • 至少包含一个特殊字符(非字母数字字符)。

PasswordHintText 属性中包含的密码要求将显示给用户。

如果用户输入的密码不符合 NewPasswordRegularExpression 属性的要求,则向用户显示 NewPasswordRegularExpressionErrorMessage 属性中包含的文本。如果未输入新密码,则向用户显示 NewPasswordRequiredErrorMessage 属性中包含的文本。

说明:

新密码必须符合由成员资格提供程序在下列属性中设置的最低要求:MinRequiredPasswordLengthMinRequiredNonAlphanumericCharactersPasswordStrengthRegularExpression 属性。如果密码不符合上述这些要求,将引发 ChangePasswordError 事件。

<%@ 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>

请参见

参考

ChangePassword

其他资源

登录工具箱控件