MembershipValidatePasswordEventHandler 委托

定义

表示将处理 MembershipProvider 类的 ValidatingPassword 事件的方法。Represents the method that will handle the ValidatingPassword event of the MembershipProvider class.

public delegate void MembershipValidatePasswordEventHandler(System::Object ^ sender, ValidatePasswordEventArgs ^ e);
public delegate void MembershipValidatePasswordEventHandler(object sender, ValidatePasswordEventArgs e);
type MembershipValidatePasswordEventHandler = delegate of obj * ValidatePasswordEventArgs -> unit
Public Delegate Sub MembershipValidatePasswordEventHandler(sender As Object, e As ValidatePasswordEventArgs)

参数

sender
Object

引发 MembershipProvider 事件的 ValidatingPasswordThe MembershipProvider that raised the ValidatingPassword event.

e
ValidatePasswordEventArgs

包含事件数据的 ValidatePasswordEventArgs 对象。A ValidatePasswordEventArgs object that contains the event data.

继承
MembershipValidatePasswordEventHandler

示例

下面的代码示例演示了ValidatingPassword一个事件, 该事件验证用户的密码格式, 然后在密码与所需格式不匹配时取消该操作。The following code example shows a ValidatingPassword event that validates the format of the password for the user, and then 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

注解

为成员资格提供程序的ValidatingPassword事件定义了委托。MembershipValidatePasswordEventHandlerThe MembershipValidatePasswordEventHandler delegate is defined for the ValidatingPassword event for a membership provider. 当调用成员资格提供程序CreateUser的方法、 ChangePassword方法或ResetPassword方法时, 将引发事件。ValidatingPasswordThe ValidatingPassword event is raised when the CreateUser method, the ChangePassword method, or the ResetPassword method of a membership provider is called.

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

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

如果通过将Cancel属性设置为true取消当前操作FailureInformation , 则可以将提供ValidatePasswordEventArgs的的属性设置为描述密码验证失败原因的异常。If you cancel the current action by setting the Cancel property to true, you can set the FailureInformation property of the supplied ValidatePasswordEventArgs 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.

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。Gets an object that represents the method represented by the specified delegate.

适用于

另请参阅