Masterly.Hash.Policy
2.0.0
dotnet add package Masterly.Hash.Policy --version 2.0.0
NuGet\Install-Package Masterly.Hash.Policy -Version 2.0.0
<PackageReference Include="Masterly.Hash.Policy" Version="2.0.0" />
<PackageVersion Include="Masterly.Hash.Policy" Version="2.0.0" />
<PackageReference Include="Masterly.Hash.Policy" />
paket add Masterly.Hash.Policy --version 2.0.0
#r "nuget: Masterly.Hash.Policy, 2.0.0"
#:package Masterly.Hash.Policy@2.0.0
#addin nuget:?package=Masterly.Hash.Policy&version=2.0.0
#tool nuget:?package=Masterly.Hash.Policy&version=2.0.0
Masterly.Hash.Policy

Password quality checks for sign-up and password-change forms, aligned with NIST SP 800-63B rev. 4, plus a zxcvbn-inspired strength estimator. Companion to Masterly.Hash.
dotnet add package Masterly.Hash.Policy
Quickstart
using Masterly.Hash;
using Masterly.Hash.Policy;
var policy = new PasswordPolicy(new PasswordPolicyOptions { ContextWords = { "Contoso" } });
PasswordPolicyResult result = policy.Evaluate(input, new PasswordContext
{
UserName = user.UserName,
Email = user.Email,
DisplayName = user.FullName,
});
if (!result.IsAcceptable)
return BadRequest(new { errors = result.Violations.Select(v => v.Message), result.Suggestions });
user.PasswordHash = Password.Hash(input);
With a breached-password corpus (you supply the implementation, e.g. a Pwned Passwords k-anonymity client):
var policy = new PasswordPolicy(new PasswordPolicyOptions(), myBreachChecker);
var result = await policy.EvaluateAsync(input, context, cancellationToken);
if (result.BreachCheckUnavailable)
logger.LogWarning("Breach corpus unavailable; password accepted on local checks only.");
Stand-alone strength meter:
StrengthEstimate estimate = PasswordStrengthEstimator.Estimate(input, new[] { user.UserName });
// estimate.Score (0-4), estimate.GuessesLog10, estimate.CrackTimes.OfflineSlowHash.Display,
// estimate.Warning, estimate.Suggestions
Rules
| Check | Default | Violation |
|---|---|---|
| Minimum length, in Unicode code points after NFKC | 15 (NIST, password as the only factor). 8 is allowed when the password is one factor of MFA; lower values are refused. | TooShort |
| Maximum length | 128 (must be 64-4096; NIST: permit at least 64) | TooLong |
Blocklist: the 10,000 most common passwords, case- and l33t-insensitive, plus BlockedPasswords |
on | CommonPassword |
Context words: user name, email local part and domain, display name, service name, extra words; also reversed, and l33t-insensitive on both sides (j0hnd03 blocks johndoe and vice versa) |
on, words of 4+ code points | ContainsContextWord |
Only repeats of short or patterned units, sequences and keyboard runs (aaaaaa, aabaabaab, 1234abcd, qwertyuiop), checked over the whole password. A strong token typed twice is left to the score. |
on | RepetitiveOrSequential |
Strength score below MinimumScore |
3 (≥ 10^8 estimated guesses) | TooWeak |
Breached-password lookup (EvaluateAsync with an IBreachedPasswordChecker) |
off until you supply one | Breached |
There are no composition rules (upper case, digit, symbol) and no expiry: NIST SP 800-63B says verifiers SHALL NOT impose them. Force a change only on evidence of compromise. All characters, including spaces and emoji, are allowed.
Strength estimator
PasswordStrengthEstimator is inspired by zxcvbn (Wheeler, USENIX Security
2016). It is an independent implementation of the same approach, not a port, and its numbers differ from zxcvbn's:
- matchers for dictionary words (embedded common-password list ranked by frequency, a small English word list and your context words), reversed words, l33t substitutions, QWERTY and keypad patterns, sequences, repeats, years and dates, with bruteforce for the rest;
- a dynamic-programming search for the decomposition needing the fewest guesses;
GuessesLog10, a 0-4Scorewith zxcvbn's thresholds (10^3, 10^6, 10^8, 10^10), crack-time estimates for online throttled (100/hour), online unthrottled (10/s), offline slow hash (10^4/s) and offline fast hash (10^10/s) attacks, and warning/suggestion text.
Only the first 100 characters are analyzed (IsTruncated tells you), which bounds the cost of a call; the estimate
of a longer password is that of its first 100 characters, an approximation rather than a bound. The policy's own
rules (length, blocklist, context words, repetitive/sequential) always look at the whole password.
Security notes
PasswordPolicyResult.ToString(),IsAcceptable,Score,Violations,SuggestionsandStrengthEstimate.Warningnever contain any part of the password and are safe to log.StrengthEstimatedetails are derived from the password:Sequencegives the position and length of each word, and the guess count of a weak password reflects the rank of the list entry it matched. Show them to the user who typed the password, but do not log, serialize or storeresult.StrengthEstimate. To limit leakage, guesses and crack times are rounded down to a tenth of a decade and individual patterns carry no guess counts.IBreachedPasswordCheckerimplementations must not send the password anywhere; use k-anonymity (send a short hash prefix only). A checker that throws or returnsUnavailabledoes not block the user; the outcome is reported inBreachCheck.- Strength estimates model a guessing attacker; they are heuristics, not guarantees. The real defence against offline attacks is the slow hash, so keep hashing with Masterly.Hash.
SensitiveStringoverloads keep passwords out of logs in request models.
Third-party material: see THIRD-PARTY-NOTICES.txt (SecLists, MIT).
| Product | Versions 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. |
-
net8.0
- Masterly.Hash (>= 2.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Masterly.Hash.Policy:
| Package | Downloads |
|---|---|
|
Masterly.Hash.Pwned
Have I Been Pwned "Pwned Passwords" k-anonymity client for Masterly.Hash: implements IBreachedPasswordChecker from Masterly.Hash.Policy. Sends only the first 5 hex characters of the password's SHA-1 hash, requests padded responses, fails open (or throws) on outages and timeouts, and offers a bounded in-memory range cache plus an AddPwnedPasswords() typed HttpClient registration. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0 | 113 | 11/3/2026 |