MembershipValidatePasswordEventHandler Delegado

Definición

Representa el método que controlará el evento ValidatingPassword de la clase MembershipProvider.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)

Parámetros

sender
Object

La clase MembershipProvider que provocó el evento ValidatingPassword.The MembershipProvider that raised the ValidatingPassword event.

e
ValidatePasswordEventArgs

Objeto ValidatePasswordEventArgs que contiene los datos del evento.A ValidatePasswordEventArgs object that contains the event data.

Ejemplos

En el ejemplo de código siguiente se muestra un ValidatingPassword evento que valida el formato de la contraseña del usuario y, a continuación, cancela la acción si la contraseña no coincide con el formato requerido.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

Comentarios

El MembershipValidatePasswordEventHandler delegado se define para el ValidatingPassword evento de un proveedor de pertenencia.The MembershipValidatePasswordEventHandler delegate is defined for the ValidatingPassword event for a membership provider. El ValidatingPassword evento se genera cuando CreateUser se llama al método, el ChangePassword método o el ResetPassword método de un proveedor de pertenencia.The ValidatingPassword event is raised when the CreateUser method, the ChangePassword method, or the ResetPassword method of a membership provider is called.

Puede usar el ValidatingPassword evento para validar formatos y valores de contraseña para usuarios de pertenencia.You can use the ValidatingPassword event to validate password formats and values for membership users.

Puede cancelar la acción actual CreateUser , ChangePassword o estableciendo ResetPassword la Cancel propiedad del proporcionado ValidatePasswordEventArgs en true durante el ValidatingPassword evento.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.

Si cancela la acción actual estableciendo la Cancel propiedad en true , puede establecer la FailureInformation propiedad del proporcionado ValidatePasswordEventArgs en una excepción que describe el motivo del error de validación de contraseña.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. El método de llamada producirá la excepción de que la FailureInformation propiedad está establecida en.The calling method will throw the exception that the FailureInformation property is set to. Si la FailureInformation propiedad es null , el autor de la llamada producirá una excepción de error de validación de contraseña genérica.If the FailureInformation property is null, the caller will throw a generic password-validation failure exception.

Métodos de extensión

GetMethodInfo(Delegate)

Obtiene un objeto que representa el método representado por el delegado especificado.Gets an object that represents the method represented by the specified delegate.

Se aplica a