Membership.GeneratePassword Method (Int32, Int32)
Generates a random password of the specified length.
Assembly: System.Web (in System.Web.dll)
static member GeneratePassword : length:int * numberOfNonAlphanumericCharacters:int -> string
Parameters
- length
-
Type:
System.Int32
The number of characters in the generated password. The length must be between 1 and 128 characters.
- numberOfNonAlphanumericCharacters
-
Type:
System.Int32
The minimum number of non-alphanumeric characters (such as @, #, !, %, &, and so on) in the generated password.
| Exception | Condition |
|---|---|
| ArgumentException | length is less than 1 or greater than 128 -or- numberOfNonAlphanumericCharacters is less than 0 or greater than length. |
The GeneratePassword method is used to generate a random password and is most commonly used by the ResetPassword 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 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 property and the numberOfNonAlphanumericCharacters parameter. |
The following code example creates a new membership user and uses the GeneratePassword method to initialize the password for the new user to a random value, which is displayed to the user.
Security Note
|
|---|
This example contains a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview. |
Available since 2.0
.jpeg?cs-save-lang=1&cs-lang=fsharp)
.jpeg?cs-save-lang=1&cs-lang=fsharp)