Masterly.Hash.Testing 2.0.0

dotnet add package Masterly.Hash.Testing --version 2.0.0
                    
NuGet\Install-Package Masterly.Hash.Testing -Version 2.0.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="Masterly.Hash.Testing" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Masterly.Hash.Testing" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Masterly.Hash.Testing" />
                    
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 Masterly.Hash.Testing --version 2.0.0
                    
#r "nuget: Masterly.Hash.Testing, 2.0.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 Masterly.Hash.Testing@2.0.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=Masterly.Hash.Testing&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Masterly.Hash.Testing&version=2.0.0
                    
Install as a Cake Tool

Masterly.Hash.Testing

Masterly.Hash: password hashing you can't get wrong.

Test helpers for applications that use Masterly.Hash. Reference it from test projects only.

Helper What it does
FastPasswordHasher A real PasswordHasher with a tiny Argon2id profile (test-fast: 64 KiB, t=1). Same behaviour as production (rehash on login, 1.x hashes, peppers, VerifyOrDummy, wrapping), microseconds per call.
RecordingPasswordHasher Decorator that records every call (operation, sync/async, stored hash, result) so you can assert how your code uses the hasher. Never records passwords.
FakePepper Deterministic, instrumented IPasswordPepper with key ids, rotation, retirement, async delay and fault injection.
MasterlyHashAssert Framework-agnostic assertions; failures throw MasterlyHashAssertionException.
KnownHashes Verified sample hashes (1.x, test-fast, peppered, wrapped, every built-in profile) and deterministic factories.

Install

dotnet add package Masterly.Hash.Testing

Quickstart

// Register the fast hasher in place of the production one.
services.AddSingleton<IPasswordHasher>(new FastPasswordHasher());

// Or wrap it to assert on usage.
var hasher = new RecordingPasswordHasher();          // wraps a FastPasswordHasher
var accounts = new AccountService(hasher, repository);

repository.Add("alice", KnownHashes.V1Sha512);        // a Masterly.Hash 1.x hash
await accounts.LoginAsync("alice", KnownHashes.Password);
MasterlyHashAssert.PersistedRehash(hasher, repository.HashOf("alice"));
MasterlyHashAssert.UsesProfile(repository.HashOf("alice"), FastPasswordHasher.ProfileId);

await accounts.LoginAsync("nobody", "whatever");
MasterlyHashAssert.UsedVerifyOrDummyForUnknownUser(hasher);

// Peppers and key rotation.
var pepper = new FakePepper("k1");
var peppered = new FastPasswordHasher(o => o.Pepper = pepper);
string stored = peppered.Hash("hunter2!");
MasterlyHashAssert.IsPeppered(stored, "k1");
pepper.RotateTo("k2");
MasterlyHashAssert.NeedsRehash(peppered, stored);

// Leak checks on whatever your code persisted.
MasterlyHashAssert.IsNotPlaintext(stored, "hunter2!");

Security notes

  • Never use FastPasswordHasher or FakePepper in production. The test-fast profile has no meaningful cost and the fake pepper's keys are public.
  • Safety net: hashes from FastPasswordHasher carry profile id test-fast, which a production PasswordHasher rejects (UnknownProfile), so a test hash that leaks into a real database can never be accepted.
  • RecordingPasswordHasher stores only an HMAC-SHA256 fingerprint of each password, keyed per recorder; compare with recorder.Fingerprint(password) or recorder.CallsWithPassword(password).
  • MasterlyHashAssert messages never include passwords or stored values.
  • IsMasterlyHash/UsesProfile/IsPeppered also check salt and tag lengths, so a hash truncated by a too-short column fails.
  • UsedVerifyOrDummyForUnknownUser fails if any unknown-user path called Verify(password, null), even if another path used VerifyOrDummy.
  • IsNotPlaintext tries UTF-8, UTF-16LE and NFKC forms of the password (plain, base64, hex and unsalted MD5/SHA-1/SHA-2 digests).
  • Assertions that take a hasher unwrap a RecordingPasswordHasher, so they never add calls to the history you assert on.
  • KnownHashes use fixed, public salts. Never seed a real database with them.
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.

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
2.0.0 80 11/3/2026