Skip to main content
๐Ÿ“œ 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:

  1. Register(username, password, byte[] salt) โ€” stores the PBKDF2 hash (KdfShape.Derive(password, salt, 100_000), hex via KdfShape.Hex); registering an existing username throws System.InvalidOperationException.
  2. Validate(username, password) โ€” true only for an existing user whose recomputed hash matches; unknown user or wrong password โ†’ false, never throws.
  3. 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).
  4. FindUsername(string raw) โ€” treats the input strictly as data and returns the matching username or null (an injection-shaped input is just a non-existent username โ€” the store is parameterized by construction).
  5. OpenFile(string baseDir, string userPath) โ€” returns the resolved path or null when 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)