Share via


ChangePassword 建構函式

定義

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

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

範例

下列程式碼範例示範如何設定 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>

適用於

另請參閱