Export (0) Print
Expand All

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.


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.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.

© 2014 Microsoft