Table of Contents

Class RandomPasswordGenerator

Namespace
Ddth.Utilities
Assembly
Ddth.Utilities.dll

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

PasswordOptions

Methods

GenerateRandomPassword()

Generates a random password with default strength requirements DefaultPasswordOptions.

public static string GenerateRandomPassword()

Returns

string

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 PasswordOptions

A valid PasswordOptions object containing the password strength requirements.

lowercaseChars string

Optional set of lowercase characters to use when generating the password.

uppercaseChars string

Optional set of uppercase characters to use when generating the password.

digitChars string

Optional set of digit characters to use when generating the password.

specialChars string

Optional set of special characters to use when generating the password.

Returns

string

Remarks

Exceptions

ArgumentException

Thrown when the given character sets do not contain enough unique characters to satisfy the required unique characters.