Lion Cipher Lab

Add TOTP two-factor auth to a web app you build

Why it matters

Turning on 2FA is a checkbox for a user; building it is a rite of passage for a developer, and it is where a surprising number of real applications get it subtly wrong. Plenty of tutorials will show you the happy path -- make a secret, show a QR, check the code -- and stop exactly where the security starts. The parts they skip are the parts attackers and auditors care about: was the shared secret encrypted before it hit the database, or sitting there in plaintext for the next breach to scoop up? Can a user who loses their phone still get in without a support-desk backdoor? Can an attacker…

What you'll learn

Steps in this lab

  1. What you're building, and the one idea it rests on
  2. Stand up the app and its dependencies
  3. Mint a per-user shared secret -- and never in plaintext
  4. Show the QR the user scans to enrol
  5. Verify the login code -- with a drift window
  6. Give users a way back in: one-time backup codes
  7. Make the endpoint hostile to guessing: rate-limit
  8. Know the ceiling: TOTP can still be phished

Open the full interactive lab →