Export (0) Print
Expand All

SqlMembershipProvider.GeneratePassword Method

Generates a random password that is at least 14 characters long.

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

public virtual string GeneratePassword()

Return Value

Type: System.String
A random password that is at least 14 characters long.

The Membership class provides a GeneratePassword method, which generates a password of a specified size with at least the specified number of non-alphabetic characters. The GeneratePassword method of the SqlMembershipProvider calls the GeneratePassword method of the Membership class to retrieve a random password that is at least 14 characters long. If the MinRequiredPasswordLength property is greater than 14, the password returned will be the length specified in the MinRequiredPasswordLength property.

You can specifically call the GeneratePassword method by referencing the SqlMembershipProvider 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.

NoteNote

The random password created by the GeneratePassword 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.

The following code example generates a random 10-character password.

SqlMembershipProvider p = (SqlMembershipProvider)Membership.Provider;
string newPassword = p.GeneratePassword();

.NET Framework

Supported in: 4.6, 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