Skip to content

About

Generates strong, cryptographically random passwords in .NET that meet OWASP rules: configurable length and minimum lowercase, uppercase, digit and special characters. DI-friendly, with span and pinned zeroed buffers, ambiguous-character exclusion and entropy estimates.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

271 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

NCode Group

NCode.PasswordGenerator

NuGet version NuGet downloads CI Target framework License OpenSSF Scorecard OpenSSF Best Practices

NCode.PasswordGenerator is a .NET library that generates cryptographically random passwords that meet configurable rules. You can use it with dependency injection or on its own.

Issues and discussion are welcome, and code is by invitation while the design settles, as CONTRIBUTING.md says.

Installation

.NET 10 or later. The package targets net10.0. Version 1.x targets .NET Standard 2.1, for apps on older runtimes.

Add the package to a project:

dotnet add package NCode.PasswordGenerator

Quick start

With dependency injection, register the generator and take IPasswordGenerator in a constructor:

using NCode.PasswordGenerator;

builder.Services.AddPasswordGenerator();

public class AccountService(IPasswordGenerator passwordGenerator)
{
    public string CreateTemporaryPassword() => passwordGenerator.Generate();
}

Without dependency injection, use the default generator:

using NCode.PasswordGenerator;

string password = PasswordGenerator.Default.Generate();

Usage

Set the rules for one call

using NCode.PasswordGenerator;

string password = PasswordGenerator.Default.Generate(options => options
    .SetLengthRange(20, 32)
    .SetMinSpecialCharacters(2)
    .SetExcludedCharacters(PasswordGeneratorOptions.AmbiguousCharacters));

The callback applies to a copy of the generator's options, so the generator's own options stay unchanged.

More

The package README is the full guide: the options and their defaults, binding from configuration, spans, pinned buffers, errors and entropy. It is also the page that nuget.org shows.

Repository layout

Path Contents
src/NCode.PasswordGenerator/ The library and its package.
tests/NCode.PasswordGenerator.Tests/ The unit tests. See its README.
docs/ The architecture, the assurance case and the decision records. See its README.
build/ The Definition of Done script and the build helpers.

Building from source

The quickest way to start is the dev container: open the repository in a GitHub Codespace, or in VS Code with the Dev Containers extension, and .devcontainer/devcontainer.json installs PowerShell 7 and the project's tools and packages, so the commands below run as they are.

From the repository root, in PowerShell 7:

dotnet build
dotnet test
./build/dod.ps1

CONTRIBUTING.md lists the prerequisites and describes the workflow.

Project

License

NCode.PasswordGenerator is licensed under the Apache License 2.0.

About

Generates strong, cryptographically random passwords in .NET that meet OWASP rules: configurable length and minimum lowercase, uppercase, digit and special characters. DI-friendly, with span and pinned zeroed buffers, ambiguous-character exclusion and entropy estimates.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages