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 Constructor

Creates a new instance of the ValidatePasswordEventArgs class.

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

public ValidatePasswordEventArgs(
	string userName,
	string password,
	bool 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 override bool ChangePassword(string username, string oldPwd, string newPwd)
{
  if (!ValidateUser(username, oldPwd))
  {
    return false;
  }

  ValidatePasswordEventArgs args =
    new ValidatePasswordEventArgs(username, newPwd, true);

  OnValidatingPassword(args);

  if (args.Cancel)
    if (args.FailureInformation != null)
      throw args.FailureInformation;
    else 
      throw new MembershipPasswordException("Change password canceled due to new password validation failure.");


  OdbcConnection conn = new OdbcConnection(ConnectionString);
  OdbcCommand cmd = 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;


  int rowsAffected = 0;

  try
  {
    conn.Open();

    rowsAffected = cmd.ExecuteNonQuery();
  }
  catch (OdbcException)
  {
    // Handle exception.
  }
  finally
  {
    conn.Close();
  }

  if (rowsAffected > 0)
  {
    return true;
  }

  return false;
}

.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