Share via


ChangePassword.NewPasswordRegularExpression 屬性

定義

取得或設定用來驗證使用者提供之密碼的規則運算式。

public:
 virtual property System::String ^ NewPasswordRegularExpression { System::String ^ get(); void set(System::String ^ value); };
public virtual string NewPasswordRegularExpression { get; set; }
member this.NewPasswordRegularExpression : string with get, set
Public Overridable Property NewPasswordRegularExpression As String

屬性值

用來驗證使用者提供之新密碼的規則運算式字串。 預設為 Empty

範例

下列程式碼範例示範如何設定 NewPasswordRegularExpression 屬性來定義正則運算式,以檢查密碼以確保其符合下列準則:

  • 大於六個字元。

  • 至少包含一個數位。

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

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

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

注意

新的密碼也必須符合 、 MinRequiredNonAlphanumericCharactersPasswordStrengthRegularExpression 屬性中 MinRequiredPasswordLength成員資格提供者所設定的最低需求。 如果密碼不符合這些需求,就會 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>

備註

NewPasswordRegularExpression使用 屬性來定義用來驗證網站上使用者帳戶的密碼需求。 這個正則運算式是用來在用戶端強制執行密碼規則。 NewPasswordRegularExpression與可在資料存放區層級設定的密碼強制執行無關。 密碼必須符合 、 MinRequiredNonAlphanumericCharactersPasswordStrengthRegularExpression 屬性中 MinRequiredPasswordLength成員資格提供者所設定的最低需求。 如果密碼不符合這些需求,就會 ChangePasswordError 引發 事件。

若要向使用者顯示需求,請設定 PasswordHintText 屬性。

如果輸入的密碼未傳遞 屬性中包含的 NewPasswordRegularExpression 正則運算式,則會向使用者顯示內容中包含的 NewPasswordRegularExpressionErrorMessage 文字。

如果成員資格提供者拒絕密碼,則會顯示 屬性中包含的 ChangePasswordFailureText 文字。

常見的密碼標準用法是強制使用者選取強式密碼。 最佳做法是在成員資格提供者的資料層級強制執行密碼規則。 屬性 NewPasswordRegularExpression 可讓您方便檢查用戶端的密碼,但不會鎖定嘗試重複登入的使用者。 若要改善安全性,請將您的成員資格提供者設定為限制使用者可能登入的嘗試次數。 如需詳細資訊,請參閱 保護成員資格

適用於

另請參閱