ValidatePasswordEventArgs.Cancel Property

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

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

'Declaration
Public Property Cancel As Boolean
'Usage
Dim instance As ValidatePasswordEventArgs
Dim value As Boolean

value = instance.Cancel

instance.Cancel = value
/** @property */
public boolean get_Cancel ()

/** @property */
public void set_Cancel (boolean value)

public function get Cancel () : boolean

public function set Cancel (value : boolean)

Not applicable.

Property Value

true if the current create-user, change-password, or reset-password action will be canceled; otherwise, false. The default is false.

The Cancel property is used to cancel the current CreateUser, ChangePassword, or ResetPassword action. You can cancel the current 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 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

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

ADD
Show: