This documentation is archived and is not being maintained.

ActiveDirectoryMembershipProvider.GeneratePassword Method

Generates a random password.

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

public virtual string GeneratePassword()

Return Value

Type: System.String
A random password.

The GeneratePassword method of the ActiveDirectoryMembershipProvider class calls the GeneratePassword method of the Membership class to retrieve a random password. The password length is set to the value of the MinRequiredPasswordLength property. The password length can never be less than 14.

You can specifically call the GeneratePassword method by referencing the ActiveDirectoryMembershipProvider class directly from the Provider property of the Membership class.

The generated password only contains alphanumeric characters and the following punctuation marks: !@#$%^&*()_-+=[{]};:<>|./?. No hidden or non-printable control characters are included in the generated password.

The generated password will contain at least the number of non-alphanumeric characters specified in the MinRequiredNonAlphanumericCharacters property. The generated password will not be tested with the regular expression in the PasswordStrengthRegularExpression property.

NoteNote

The ActiveDirectoryMembershipProvider class does not generate passwords that match complexity requirements set in the directory. It is possible to generate a random password that fails the password complexity rules set by the directory.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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