Practice ยท 3 of 4
Salted, Slow, and Recomputable
UserStore stores SHA256(password) directly โ fast, unsalted,
reversible by lookup tables. Replace it with the standard shape using the
provided KdfShape primitive (PBKDF2-SHA256, 32 bytes):
``csharp
public static class Solution
{
public static string HashPassword(string password, byte[] salt); // hex, 100_000 iterations
public static bool Verify(string password, byte[] salt, string storedHex);
public static void RequireSalt(byte[] salt); // throws ArgumentException when salt is null or shorter than 16 bytes
}
`
Rules:
- HashPassword calls RequireSalt first, then derives via
KdfShape.Derive(password, salt, 100_000) and returns the lowercase hex โ
the test computes the same reference and compares exactly,
- Verify treats a null or too-short salt as a failed verification
(false) โ it must never throw for bad inputs; otherwise it recomputes
with the stored salt and returns whether the hex matches,
- wrong password โ false`, never an exception.
Back to lesson: Practice: Security Practice: Barriers at the Boundary