System.Web.Security.Membership.GeneratePassword Method

Generates a random password of the specified length.

Syntax

public static string GeneratePassword (int length, int numberOfNonAlphanumericCharacters)

Parameters

length
The number of characters in the generated password. The length must be between 1 and 128 characters.
numberOfNonAlphanumericCharacters
The minimum number of non-alphanumeric characters (such as @, #, !, %, &, and so on) in the generated password.

Returns

A random password of the specified length.

Remarks

The Membership.GeneratePassword(int, int) method is used to generate a random password and is most commonly used by the MembershipProvider.ResetPassword(string, string) method implemented by a membership provider to reset the password for a user to a new, temporary password.

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.

Note:

The random password created by the Membership.GeneratePassword(int, int) method is not guaranteed to pass the regular expression in the Membership.PasswordStrengthRegularExpression property. However, the random password will meet the criteria established by the Membership.MinRequiredPasswordLength property and the numberOfNonAlphanumericCharacters parameter.

Requirements

Namespace: System.Web.Security
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0