共用方式為


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 傳輸可能會受到惡意使用者的檢視或危害。若要改善使用登入控制項時的安全性,應使用具有 Secure Sockets Layer (SSL) 加密的 HTTPS 通訊協定,以確保使用者的密碼在回傳期間無法被讀取。如需詳細資訊,請參閱 設定登入控制項的安全性

ChangePassword 控制項使用 MembershipProvider 屬性中定義的成員資格提供者,變更網站之成員資格提供者資料存放區中儲存的密碼。如果未指派成員資格提供者,ChangePassword 控制項會使用定義於 Web.config 檔案之 membership 區段的預設成員資格提供者。

如需使用 ChangePassword 控制項和其他 ASP.NET 登入控制項的詳細資訊,請參閱 ASP.NET 登入控制項概觀

範例

下列程式碼範例示範如何設定 NewPasswordRegularExpression 屬性,定義檢查密碼的規則運算式 (Regular Expression) 以確保密碼符合下列準則:

  • 多於 6 個字元。

  • 至少包含一位數字。

  • 至少包含一個特殊 (非英數) 字元。

PasswordHintText 屬性中包含的密碼需求會顯示給使用者。

如果使用者輸入的密碼不符合 NewPasswordRegularExpression 屬性的需求,便會向使用者顯示 NewPasswordRegularExpressionErrorMessage 屬性中包含的文字。如果未輸入新密碼,則會向使用者顯示 NewPasswordRequiredErrorMessage 屬性中包含的文字。

注意事項:

新密碼必須符合由 MinRequiredPasswordLengthMinRequiredNonAlphanumericCharactersPasswordStrengthRegularExpression 屬性中之 membership provider 設定的最小需求。如果密碼不符合這些需求,將引發 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

其他資源

登入工具箱控制項