Simple.PasswordGenerator is a lightweight, secure password generator for .NET applications. It creates cryptographically strong passwords based on customizable policies — including length, required character types, and special characters. No dependencies beyond .NET. Simple to integrate, flexible to configure, and safe to use.
$ dotnet add package Simple.PasswordGeneratorSimple.PasswordGenerator is a lightweight, secure password generator for .NET applications.
It creates cryptographically strong passwords based on customizable policies — including length, required character types, special characters, and the ability to exclude ambiguous characters for better readability.
No dependencies beyond .NET. Simple to integrate, flexible to configure, and safe to use.
Use Simple.PasswordGenerator to generate strong, policy-compliant passwords easily.
Add the package via NuGet:
dotnet add package Simple.PasswordGenerator
var generator = new PasswordGenerator();
var password = generator.Generate();
Console.WriteLine($"Generated password: {password}");
Configure a custom password policy using a lambda:
var password = generator.Generate(policy =>
{
policy.Length = 20;
policy.RequireSpecial = false;
policy.RequireDigit = true;
policy.RequireUppercase = true;
policy.RequireLowercase = true;
policy.ExcludeAmbiguousCharacters = true;
});
Or generate using a predefined PasswordPolicy object:
var policy = new PasswordPolicy
{
Length = 12,
RequireSpecial = true,
RequireDigit = true,
RequireUppercase = false,
RequireLowercase = true,
SpecialCharacters = "@#$",
ExcludeAmbiguousCharacters = true,
AmbiguousCharacters = "O0Il1"
};
var passwordFromPolicy = generator.Generate(policy);
You can generate a password and receive detailed strength information including entropy and strength category:
var strengthResult = generator.GenerateWithStrength(policy =>
{
policy.Length = 16;
policy.RequireUppercase = true;
policy.RequireLowercase = true;
policy.RequireDigit = true;
policy.RequireSpecial = true;
});
Console.WriteLine($"Password: {strengthResult.Password}");
Console.WriteLine($"Entropy (bits): {strengthResult.EntropyBits}");
Console.WriteLine($"Strength: {strengthResult.Strength}");
using Simple.PasswordGenerator;
var passwordGenerator = new PasswordGenerator();
// Default policy password
var defaultPassword = passwordGenerator.Generate();
Console.WriteLine($"Default policy password: {defaultPassword}");
// Custom policy via lambda
var customPassword = passwordGenerator.Generate(policy =>
{
policy.Length = 20;
policy.RequireSpecial = false;
policy.RequireDigit = true;
policy.RequireUppercase = true;
policy.RequireLowercase = true;
policy.ExcludeAmbiguousCharacters = true;
});
Console.WriteLine($"Custom policy password: {customPassword}");
// Using a PasswordPolicy instance
var policyInstance = new PasswordPolicy
{
Length = 12,
RequireSpecial = true,
RequireDigit = true,
RequireUppercase = false,
RequireLowercase = true,
SpecialCharacters = "@#$",
ExcludeAmbiguousCharacters = true,
AmbiguousCharacters = "O0Il1"
};
var policyPassword = passwordGenerator.Generate(policyInstance);
Console.WriteLine($"Password from policy instance: {policyPassword}");
// Generate password with strength info
var strengthResult = passwordGenerator.GenerateWithStrength(policy =>
{
policy.Length = 16;
policy.RequireUppercase = true;
policy.RequireLowercase = true;
policy.RequireDigit = true;
policy.RequireSpecial = true;
});
Console.WriteLine($"Password: {strengthResult.Password}");
Console.WriteLine($"Entropy (bits): {strengthResult.EntropyBits}");
Console.WriteLine($"Strength: {strengthResult.Strength}");
System.Security.Cryptography.RandomNumberGenerator for cryptographically secure randomizationBug reports, feature requests, and pull requests are welcome!
Please open an issue or submit a PR via GitHub Issues.
This project is licensed under the MIT License.