語言

ChangePassword 建構函式

定義

初始化 ChangePassword 類別的新執行個體。

public:
 ChangePassword();
public ChangePassword();
Public Sub New ()

範例

以下程式碼範例說明如何設定 NewPasswordRegularExpression 屬性以定義一個正則表達式,檢查密碼以確保符合以下條件:

  • 大於六個字元。

  • 至少包含一個數字。

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

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

若使用者輸入的密碼不符合條件,該屬性中的文字 NewPasswordRegularExpressionErrorMessage 會顯示給使用者。 若未輸入新密碼,該屬性中的 NewPasswordRequiredErrorMessage 文字會顯示給使用者。

Note

新密碼必須符合會員提供者MinRequiredPasswordLength在 、 MinRequiredNonAlphanumericCharacters及PasswordStrengthRegularExpression屬性中設定的最低要求。 若密碼不符合這些條件,事件 ChangePasswordError 將被觸發。

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

適用於

另請參閱