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.
.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.PasswordGeneratorWith 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();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.
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.
| 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. |
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.ps1CONTRIBUTING.md lists the prerequisites and describes the workflow.
- Issues: report a bug or ask for a feature.
- CONTRIBUTING.md: how to set up, build, test and propose a change.
- SECURITY.md: how to report a vulnerability privately.
- CODE_OF_CONDUCT.md, GOVERNANCE.md and ROADMAP.md: how we work together, who decides, and where the project is going.
- docs/architecture.md and docs/assurance-case.md: how the project is built, and why it meets its security requirements.
- docs/decisions/: the decisions behind the design, the project's and the template's.
- docs/replies.md: the replies the maintainers post to people outside the project.
- CHANGELOG.md: in the Keep a Changelog format, what changed in each release.
- LICENSE.txt: the license.
NCode.PasswordGenerator is licensed under the Apache License 2.0.
