KPasswordGenerator 1.2.0

dotnet add package KPasswordGenerator --version 1.2.0
                    
NuGet\Install-Package KPasswordGenerator -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KPasswordGenerator" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KPasswordGenerator" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="KPasswordGenerator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KPasswordGenerator --version 1.2.0
                    
#r "nuget: KPasswordGenerator, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KPasswordGenerator@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KPasswordGenerator&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=KPasswordGenerator&version=1.2.0
                    
Install as a Cake Tool

PasswordGenerator

A lightweight, secure, and flexible password generator library for .NET, built with cryptographic randomness and fully customizable character sets.

Build & Test NuGet


Features

  • Cryptographically secure — built on .NET’s RandomNumberGenerator for high-entropy randomness
  • Performance-focused — uses Span<char> and stack allocation to minimize heap usage and avoid unnecessary string allocations
  • Customizable character sets — define your own character pools (e.g., symbols, digits, uppercase)
  • Per-set minimum requirements — ensure that a minimum number of characters from each set are included
  • Predictable-free output — final password is securely shuffled to eliminate character order patterns
  • Ambiguity-avoiding — easily exclude confusing characters like 0, O, l, and I
  • Clean, testable design — .NET 8 compatible and unit-tested

using KPasswordGenerator;

// Define your password policy
PasswordSettings settings = new(
[
    new CharacterRequirement(minRequired: 2, characterPool: "ABCDEFGHJKLMNPQRSTUVWXYZ"),
    new CharacterRequirement(3, "abcdefghijkmnopqrstuvwxyz"),   // At least 3 lowercase letters (no l)
    new CharacterRequirement(4, "23456789"),                    // At least 4 digits (no 0, 1)
    new CharacterRequirement(2, "!@$?_-")                       // At least 2 symbols
]);

PasswordGenerator generator = new(settings);

string password = generator.Generate(16);

Console.WriteLine(password);  // Example output: kAj79uV@E?m7_8eS

Using WithDefaults

Quickly generate a password using default pools:

PasswordSettings settings = PasswordSettings.WithDefaults(minLower: 2, minUpper: 2, minDigits: 2, minSpecial: 1);
PasswordGenerator generator = new(settings);

string password = generator.Generate(12);

Additional Methods

GenerateRandomLength(int minPasswordLength, int maxPasswordLength)

Generates a password of random length within a specified range.

  • Ensures the generated password meets all defined character requirements.
  • Uses secure randomness to choose the length.

Example:

string password = generator.GenerateRandomLength(12, 20);

Validate(string password)

Validates whether a password meets the current PasswordSettings policy.

  • Checks overall length.

  • Verifies that the required number of characters from each character pool are present.

  • Returns true if all rules pass, otherwise false.

  • Example:

bool isValid = generator.Validate("abcD123!");

Installation

Install via NuGet:

dotnet add package KPasswordGenerator
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 136 7/1/2025