This documentation is archived and is not being maintained.

ValidatePasswordEventArgs Constructor

Creates a new instance of the ValidatePasswordEventArgs class.

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

'Declaration
Public Sub New ( _
	userName As String, _
	password As String, _
	isNewUser As Boolean _
)
'Usage
Dim userName As String 
Dim password As String 
Dim isNewUser As Boolean 

Dim instance As New ValidatePasswordEventArgs(userName, _
	password, isNewUser)

Parameters

userName
Type: System.String

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

password
Type: System.String

The new password for the specified membership user.

isNewUser
Type: System.Boolean

true if the event is occurring while a new user is being created; otherwise, false.

The ValidatePasswordEventArgs constructor is used by a membership provider implementation in the CreateUser, ChangePassword, and ResetPassword method implementations.

The following code example shows a sample ChangePassword implementation that creates a new ValidatePasswordEventArgs object to pass to the ValidatingPassword event.

Public Overrides Function ChangePassword(username As String, _
                                         oldPwd As String, _
                                         newPwd As String) As Boolean 

  If Not ValidateUser(username, oldPwd) Then 
    Return False 
  End If 

  Dim args As ValidatePasswordEventArgs = _
    New ValidatePasswordEventArgs(username, newPwd, True)

  OnValidatingPassword(args)

  If args.Cancel Then 
    If Not args.FailureInformation Is Nothing Then 
      Throw args.FailureInformation
    Else 
      Throw New MembershipPasswordException("Change password canceled due to New password validation failure.")
    End If 
  End If 


  Dim conn As OdbcConnection = New OdbcConnection(ConnectionString)
            Dim cmd As OdbcCommand = New OdbcCommand("UPDATE Users " & _
                       " SET Password = ?, LastPasswordChangedDate = ? " & _
                       " WHERE Username = ? AND Password = ? AND ApplicationName = ?", conn)

  cmd.Parameters.Add("@Password", OdbcType.VarChar, 128).Value = EncodePassword(newPwd)
  cmd.Parameters.Add("@LastPasswordChangedDate", OdbcType.DateTime).Value = DateTime.Now
  cmd.Parameters.Add("@Username", OdbcType.VarChar, 255).Value = username
  cmd.Parameters.Add("@OldPassword", OdbcType.VarChar, 128).Value = oldPwd
  cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value = ApplicationName


  Dim rowsAffected As Integer = 0

  Try
    conn.Open()

    rowsAffected = cmd.ExecuteNonQuery()
  Catch e As OdbcException
    ' Handle exception. 
  Finally
    conn.Close()
  End Try 

  If rowsAffected > 0 Then Return True 

  Return False 
End Function

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: