共用方式為


CreateUserWizard.PasswordRegularExpression 屬性

定義

取得或設定規則運算式,用於驗證提供的密碼。

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

屬性值

String

包含規則運算式的字串,用於驗證提供的密碼。 預設值為空字串 ("")。

範例

下列程式碼範例會 PasswordRegularExpression 使用 屬性來定義正則運算式,以檢查密碼以確保密碼:

  • 長度超過七個字元。

  • 至少包含一位數。

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

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

<%@ 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>CreateUserWizard.PasswordRegularExpression sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:createuserwizard id="Createuserwizard1" runat="server" 
        passwordregularexpression='@\"(?:.{7,})(?=(.*\d){1,})(?=(.*\W){1,})'
        passwordregularexpressionerrormessage="Your password must be 7 characters long, and contain at least one number and one special character.">
      </asp:createuserwizard>
    </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 id="Head1" runat="server">
    <title>CreateUserWizard.PasswordRegularExpression sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:createuserwizard id="Createuserwizard1" runat="server" 
        passwordregularexpression='@\"(?:.{7,})(?=(.*\d){1,})(?=(.*\W){1,})'
        passwordregularexpressionerrormessage="Your password must be 7 characters long, and contain at least one number and one special character.">
      </asp:createuserwizard>
    </div>
    </form>
</body>
</html>

備註

PasswordRegularExpression使用 屬性來定義用來驗證您網站上使用者的密碼需求。 常見的用法是確保使用者的密碼中包含字母以外的符號,讓攻擊者難以猜測密碼。 除了屬性中所 MembershipProvider 指定成員資格提供者對密碼所做的任何限制之外,還會使用正則運算式。 如果成員資格提供者因為任何原因而拒絕密碼,則會顯示 屬性中包含的 InvalidPasswordErrorMessage 文字。

如果輸入的密碼未傳遞正則運算式,則會向使用者顯示 屬性中包含的 PasswordRegularExpressionErrorMessage 錯誤訊息。

適用於

另請參閱