๐ WAYPOINT LESSON
Checkpoint โ The Hardened User Store
โญโญ intermediateโณ 30 min read๐ Lesson 152 of 265
Compose the module: register users with per-user salts and PBKDF2, verify credentials, keep the lookup data-only, and confine every file request โ one store, all the barriers.
The gate (mini-build)
A SecureUserStore + file gateway, security-graded:
Register(username, password, byte[] salt)โ stores the PBKDF2 hash (KdfShape.Derive(password, salt, 100_000), hex viaKdfShape.Hex); registering an existing username throwsSystem.InvalidOperationException.Validate(username, password)โ true only for an existing user whose recomputed hash matches; unknown user or wrong password โfalse, never throws.- Per-user salting โ two users with the same password but different salts
must end up with different stored hashes (the test reads the store via
HashOf(username)and compares against the PBKDF2 reference). FindUsername(string raw)โ treats the input strictly as data and returns the matching username ornull(an injection-shaped input is just a non-existent username โ the store is parameterized by construction).OpenFile(string baseDir, string userPath)โ returns the resolved path ornullwhen it escapes (same rule as the practice set).
public static class Solution
{
public static void Register(string username, string password, byte[] salt);
public static bool Validate(string username, string password);
public static string HashOf(string username); // stored hash, for the test
public static string FindUsername(string raw); // data, not query text
public static string OpenFile(string baseDir, string userPath);
}
// provided: KdfShape.Derive / KdfShape.Hex (PBKDF2-SHA256, 32 bytes)