Membership.PasswordStrengthRegularExpression 属性

定义

获取用于计算密码的正则表达式。Gets the regular expression used to evaluate a password.

public:
 static property System::String ^ PasswordStrengthRegularExpression { System::String ^ get(); };
public static string PasswordStrengthRegularExpression { get; }
member this.PasswordStrengthRegularExpression : string
Public Shared ReadOnly Property PasswordStrengthRegularExpression As String

属性值

String

用于计算密码的正则表达式。A regular expression used to evaluate a password.

示例

下面的代码示例演示应用程序 Web.config 文件的部分中的 成员资格 配置元素 system.webThe following code example shows the membership configuration element in the system.web section of the application's Web.config file. 它指定应用程序使用类的实例 SqlMembershipProvider 来提供成员身份服务,并将 passwordStrengthRegularExpression 特性设置为验证密码的正则表达式是否满足以下条件:It specifies that the application use an instance of the SqlMembershipProvider class to provide membership services, and sets the passwordStrengthRegularExpression attribute to a regular expression that validates the password meets the following criteria:

  • 超过7个字符。Is greater than seven characters.

  • 包含至少一个数字。Contains at least one digit.

  • 包含至少一个特殊 (非字母数字) 字符。Contains at least one special (non-alphanumeric) character.

如果密码不符合这些条件,则成员资格提供程序不接受该密码。If the password does not meet these criteria, the password is not accepted by the membership provider.

<membership defaultProvider="SqlProvider"  
  userIsOnlineTimeWindow = "20>  
  <providers>  
    <add  
      name="SqlProvider"  
      type="System.Web.Security.SqlMembershipProvider"  
      connectionStringName="SqlServices"  
      requiresQuestionAndAnswer="true"  
      passwordStrengthRegularExpression=" @\"(?=.{6,})(?=(.*\d){1,})(?=(.*\W){1,})"  
      />  
   </providers>  
</membership>  

注解

PasswordStrengthRegularExpression属性获取用于从属性中指定的提供程序计算密码复杂性的正则表达式 ProviderThe PasswordStrengthRegularExpression property gets the regular expression used to evaluate password complexity from the provider specified in the Provider property.

PasswordStrengthRegularExpression使用 passwordStrengthRegularExpression 成员资格配置元素的特性在应用程序配置中设置属性。The PasswordStrengthRegularExpression property is set in the application configuration using the passwordStrengthRegularExpression attribute of the membership configuration element.

有关正则表达式的详细信息,请参阅 .NET Framework 正则表达式For more information about regular expressions, see .NET Framework Regular Expressions.

适用于