ChangePassword
This method updates the password for a user.
Declaration
// C# public override bool ChangePassword(string userName, string oldPassword, string newPassword);
Parameters
-
userNameThe user to update the password for.
-
oldPasswordThe current password for the specified user.
-
newPasswordThe new password for the specified user.
Return Value
Returns true if the password was updated successfully; otherwise, returns false.
Exceptions
ArgumentNullException - The userName, oldPassword, or newPassword parameter is null.
System.Web.Security.MembershipPasswordException - userName was not found in the membership database.
System.Configuration.Provider.ProviderException - An error occurred when setting the new password in the database.
Exception - An unhandled exception has occurred.
ArgumentException - One of the following conditions exists:
-
The
userNameparameter is an empty string, contains a comma, or is longer than 256 characters. -
The
oldPasswordparameter is an empty string or is longer than 128 characters. -
The
newPasswordparameter is an empty string, is longer than 128 characters (including the encoded version), is less than the value of theMinRequiredPasswordLengthproperty, has a number of nonalphanumeric characters less than the value ofMinRequiredNonAlphanumericCharactersproperty, or does not match the regular expression defined in thePasswordStrengthRegularExpressionproperty. -
The change-password operation was canceled by a subscriber to the
ValidatingPasswordevent, and theFailureInformationproperty was a null reference.
Remarks
The ChangePassword method returns true if the supplied user name and password are valid and the password was updated successfully; otherwise, it returns false.