ValidatePasswordEventArgs 类

定义

ValidatingPassword 类的 MembershipProvider 事件提供事件数据。Provides event data for the ValidatingPassword event of the MembershipProvider class.

public ref class ValidatePasswordEventArgs sealed : EventArgs
public sealed class ValidatePasswordEventArgs : EventArgs
type ValidatePasswordEventArgs = class
    inherit EventArgs
Public NotInheritable Class ValidatePasswordEventArgs
Inherits EventArgs
继承
ValidatePasswordEventArgs

示例

下面的代码示例演示了ValidatingPassword一个事件, 该事件验证用户的密码格式并在密码与所需格式不匹配时取消该操作。The following code example shows a ValidatingPassword event that validates the format of the password for the user and cancels the action if the password does not match the required format.

public void Page_Load()
{
  Membership.ValidatingPassword +=
    new MembershipValidatePasswordEventHandler(OnValidatePassword);
}

public void OnValidatePassword(object sender,
                              ValidatePasswordEventArgs args)
{
  System.Text.RegularExpressions.Regex r =
    new System.Text.RegularExpressions.Regex(@"(?=.{6,})(?=(.*\d){1,})(?=(.*\W){1,})");


  if (!r.IsMatch(args.Password))
  {
    args.FailureInformation =
      new HttpException("Password must be at least 6 characters long and " +
                        "contain at least one number and one special character.");
    args.Cancel = true;
  }
}
Public Sub Page_Load()
    AddHandler Membership.ValidatingPassword, _
    New MembershipValidatePasswordEventHandler(AddressOf OnValidatePassword)
End Sub

Public Sub OnValidatePassword(sender As Object, _
                               args As ValidatePasswordEventArgs)
  Dim r As System.Text.RegularExpressions.Regex =  _
    New System.Text.RegularExpressions.Regex("(?=.{6,})(?=(.*\d){1,})(?=(.*\W){1,})")
         

  If Not r.IsMatch(args.Password) Then
    args.FailureInformation = _
      New HttpException("Password must be at least 6 characters long and " & _
                        "contain at least one number and one special character.")
    args.Cancel = True
  End If
End Sub

注解

当调用成员资格提供程序CreateUserChangePassword、或ResetPassword方法时, 将引发事件。ValidatingPasswordThe ValidatingPassword event is raised when the CreateUser, ChangePassword, or ResetPassword method of a membership provider is called.

可以处理ValidatingPassword事件来验证成员资格用户的密码格式和值。You can handle the ValidatingPassword event to validate password formats and values for membership users.

可以CreateUser通过在ValidatingPassword事件中将ChangePassword Cancel属性设置ResetPassword为来true取消当前的、或操作。You can cancel the current CreateUser, ChangePassword, or ResetPassword action by setting the Cancel property to true during the ValidatingPassword event.

如果通过将Cancel属性设置为true取消当前操作FailureInformation , 则可以将属性设置为描述密码验证失败原因的异常。If you cancel the current action by setting the Cancel property to true, you can set the FailureInformation property to an exception that describes the reason for the password-validation failure. 调用方法将引发FailureInformation属性设置为的异常。The calling method will throw the exception that the FailureInformation property is set to. 如果属性为null, 则调用方将引发一般密码验证失败异常。 FailureInformationIf the FailureInformation property is null, the caller will throw a generic password-validation failure exception.

构造函数

ValidatePasswordEventArgs(String, String, Boolean)

创建 ValidatePasswordEventArgs 类的新实例。Creates a new instance of the ValidatePasswordEventArgs class.

属性

Cancel

获取或设置一个值,该值指示是否将取消当前的创建用户、更改密码或重置密码操作。Gets or sets a value that indicates whether the current create-user, change-password, or reset-password action will be canceled.

FailureInformation

获取或设置一个描述密码验证失败原因的异常。Gets or sets an exception that describes the reason for the password-validation failure.

IsNewUser

获取一个值,该值指示在调用 ValidatingPassword 方法期间是否引发 CreateUser(String, String, String, String, String, Boolean, Object, MembershipCreateStatus) 事件。Gets a value that indicates whether the ValidatingPassword event is being raised during a call to the CreateUser(String, String, String, String, String, Boolean, Object, MembershipCreateStatus) method.

Password

获取当前创建用户、更改密码或重置密码操作的密码。Gets the password for the current create-user, change-password, or reset-password action.

UserName

获取当前创建用户、更改密码或重置密码操作的成员资格用户名。Gets the name of the membership user for the current create-user, change-password, or reset-password action.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅