Export (0) Print
Expand All

ValidatePasswordEventArgs.FailureInformation Property

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

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

public Exception FailureInformation { get; set; }

Property Value

Type: System.Exception
An Exception that describes the reason for the password-validation failure.

The FailureInformation property is used when the current CreateUser, ChangePassword, or ResetPassword action has been canceled by setting the Cancel property to true.

The FailureInformation property is set 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

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4
Show:
© 2015 Microsoft