Interactive tool

PIN generator and verifier

Generate a PIN with a cryptographically secure random source, store only a salted hash of it, and verify attempts the way a real login system should.

1. Generate

Uses crypto.getRandomValues with rejection sampling, so each digit is uniform.

------

2. Enrol

Stores a random salt and a PBKDF2-SHA256 hash. The PIN itself is discarded.

3. Verify

Re-derives the hash and compares it in constant time. Five failures lock the attempts.

Why it is built this way

A PIN is short, so the defences around it matter more than the PIN itself.

  • Only a salted, slow hash is stored, so a leaked record does not reveal the PIN directly.
  • Each record has its own random salt, so identical PINs produce different hashes.
  • Comparison runs in constant time, so response timing does not reveal matching digits.
  • Attempts are limited. Keep the counter on the server, because a browser-side counter can be reset by anyone who can edit the page.