Class RandomPasswordGenerator
Helper class to generate random passwords, respecting the given strength requirements.
public static class RandomPasswordGenerator
- Inheritance
-
RandomPasswordGenerator
- Inherited Members
Examples
using Ddth.Utilities;
// Generate a random password with default strength requirements
var randomPassword = RandomPasswordGenerator.GenerateRandomPassword();
// Generate a random password with custom strength requirements
var passwordOptions = new PasswordOptions
{
RequiredLength = 16,
RequiredUniqueChars = 8,
RequireDigit = true,
RequireLowercase = true,
RequireUppercase = true,
RequireNonAlphanumeric = true
};
var randomPassword = RandomPasswordGenerator.GenerateRandomPassword(passwordOptions, specialChars: "!@#$%^&*()");
Fields
DefaultPasswordOptions
Default password strength requirements:
- Minimum 12 characters long
- At least 5 unique characters
- At least 1 digit
- At least 1 lowercase letter
- At least 1 uppercase letter
- No special characters
public static readonly PasswordOptions DefaultPasswordOptions
Field Value
Methods
GenerateRandomPassword()
Generates a random password with default strength requirements DefaultPasswordOptions.
public static string GenerateRandomPassword()
Returns
GenerateRandomPassword(PasswordOptions?, string, string, string, string)
Generates a random password, respecting the given strength requirements.
public static string GenerateRandomPassword(PasswordOptions? passwordOptions, string lowercaseChars = "abcdefghijklmnopqrstuvwxyz", string uppercaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", string digitChars = "0123456789", string specialChars = "!@#$%^&*()_-+=[{]};:>|./?")
Parameters
passwordOptions
PasswordOptionsA valid PasswordOptions object containing the password strength requirements.
lowercaseChars
stringOptional set of lowercase characters to use when generating the password.
uppercaseChars
stringOptional set of uppercase characters to use when generating the password.
digitChars
stringOptional set of digit characters to use when generating the password.
specialChars
stringOptional set of special characters to use when generating the password.
Returns
Remarks
Exceptions
- ArgumentException
Thrown when the given character sets do not contain enough unique characters to satisfy the required unique characters.