ValidatePasswordEventArgs Class

 

Provides event data for the ValidatingPassword event of the MembershipProvider class.

Namespace:   System.Web.Security
Assembly:  System.Web.ApplicationServices (in System.Web.ApplicationServices.dll)

System.Object
  System.EventArgs
    System.Web.Security.ValidatePasswordEventArgs

public sealed class ValidatePasswordEventArgs : EventArgs

NameDescription
System_CAPS_pubmethodValidatePasswordEventArgs(String, String, Boolean)

Creates a new instance of the ValidatePasswordEventArgs class.

NameDescription
System_CAPS_pubpropertyCancel

Gets or sets a value that indicates whether the current create-user, change-password, or reset-password action will be canceled.

System_CAPS_pubpropertyFailureInformation

Gets or sets an exception that describes the reason for the password-validation failure.

System_CAPS_pubpropertyIsNewUser

Gets a value that indicates whether the ValidatingPassword event is being raised during a call to the CreateUser method.

System_CAPS_pubpropertyPassword

Gets the password for the current create-user, change-password, or reset-password action.

System_CAPS_pubpropertyUserName

Gets the name of the membership user for the current create-user, change-password, or reset-password action.

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

The ValidatingPassword event is raised when the CreateUser, ChangePassword, or ResetPassword method of a membership provider is called.

You can handle the ValidatingPassword event to validate password formats and values for membership users.

You can cancel the current CreateUser, ChangePassword, or ResetPassword action by setting the Cancel property to true during the ValidatingPassword event.

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. The calling method will throw the exception that the FailureInformation property is set to. If the FailureInformation property is null, the caller will throw a generic password-validation failure exception.

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;
  }
}

.NET Framework
Available since 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: