Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ValidatePasswordEventArgs Class

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

Namespace: System.Web.Security
Assembly: System.Web (in system.web.dll)

public sealed class ValidatePasswordEventArgs : EventArgs
public final class ValidatePasswordEventArgs extends EventArgs
public final class ValidatePasswordEventArgs extends EventArgs
Not applicable.

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 a null reference (Nothing in Visual Basic), 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;
  }
}

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

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

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

Show:
© 2014 Microsoft