Export (0) Print
Expand All

ActiveDirectoryMembershipProvider.ResetPassword Method

Resets a user's password to a new, automatically generated password.

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

[DirectoryServicesPermissionAttribute(SecurityAction.Assert, Unrestricted = true)]
[DirectoryServicesPermissionAttribute(SecurityAction.InheritanceDemand, Unrestricted = true)]
[DirectoryServicesPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]
public override string ResetPassword(
	string username,
	string passwordAnswer
)

Parameters

username
Type: System.String

The user to reset the password for.

passwordAnswer
Type: System.String

The password answer for the specified user.

Return Value

Type: System.String
The new password for the specified user.

ExceptionCondition
InvalidOperationException

The ResetPassword method is called before the ActiveDirectoryMembershipProvider instance is initialized.

NotSupportedException

The EnablePasswordReset property value is false.

ArgumentNullException

passwordAnswer is null.

- or -

username is null.

ArgumentException

passwordAnswer is empty after trimming

- or -

passwordAnswer exceeds 128 characters.

- or -

username is empty, or exceeds the maximum length allowed for user names (usually 256 characters).

- or -

username contains commas.

- or -

The user name is mapped to userPrincipalName but the username parameter contains backslashes.

MembershipPasswordException

The user is locked out because of too many bad logon attempts or too many attempted password-answer reset attempts.

- or -

passwordAnswer does not match the stored password answer.

ProviderException

The user specified in username does not exist in the Active Directory data store.

- or -

A generated password does not pass a custom validation handler.

- or -

The generated password is not complex enough to satisfy custom password policies set on the Active Directory server.

- or -

A secure connection cannot be made to an Active Directory Application Mode server to set the new password.

Exception

An unhandled exception occurred.

The method is called by the Membership class to reset the password for a user in the Active Directory data store to a new randomly generated value. The new password is returned.

NoteNote

The random password created by the ResetPassword method is not guaranteed to pass the regular expression in the PasswordStrengthRegularExpression property. However, the random password will meet the criteria established by the MinRequiredPasswordLength and MinRequiredNonAlphanumericCharacters properties.

If an incorrect answer is supplied to the ResetPassword method, the internal counter that tracks invalid password-answer attempts is incremented by one. This can result in the user being unable to log on until the lock status is cleared by a call to the UnlockUser method. If the correct password answer is supplied and the user is not currently locked out, then the internal counter that tracks invalid password attempts is reset to zero. For more information, see the MaxInvalidPasswordAttempts and PasswordAttemptWindow properties.

Leading and trailing spaces are trimmed from all parameter values.

You can call the ResetPassword method directly by first obtaining a reference to the ActiveDirectoryMembershipProvider instance from the Membership.Provider property.

The provider uses a subtree search starting at the search point specified in the connection string. See the ActiveDirectoryMembershipProvider class topic for more information about connection strings.

To set passwords on an Active Directory server, the connectionProtection attribute must be set to SignAndSeal.

When using an ADAM server, the connectionProtection attribute can be set to None, but only if you explicitly configure the ADAM server to allow password changes over unsecured connections.

Security noteSecurity Note

You cannot reset passwords unless the credentials used to connect to the Active Directory server have either Domain Administrator rights (not recommended) or the "reset password" access right.

To reset a password, all of the following conditions must be true:

  • The EnablePasswordReset property must be set to true.

  • The Active Directory schema must be modified to contain attributes for storing the password question and answer, and the three tracking fields for password answer changes.

  • The attributeMapPasswordQuestion, attributeMapPasswordAnswer, attributMapFailedPasswordAnswerCount, attributeMapFailedPasswordAnswerTime, and attributeMapFailedPasswordAnswerLockedTime attributes must be set in the application configuration file.

  • The RequiresQuestionAndAnswer property must be set to true.

  • The security context for connecting to the Active Directory data store (either the process account or the explicit credentials) must have sufficient privileges to change passwords. The credentials used to connect to the Active Directory server have either Domain Administrator rights (not recommended) or the "reset password" access right.

NoteNote

Security policies set on the Active Directory server may make it impossible for the ResetPassword method to generate a password that satisfies the policies. The default implementation of the GeneratePassword method will generate passwords that satisfy the default password policies on domain controllers running Windows Server 2003 SP1. If the password cannot be reset due to security policies on the Active Directory server, a ProviderException is thrown.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft