Get Started
Protect your app and website

Mission 2 of 10

Build a safer login: passkeys, Argon2id and proper sessions.

Login is the first thing every attacker touches. Learn what to use in 2026 and why, then build and attack a working session-based login in under 120 lines you can read in full.

75 minIntermediateFreeStep 1 free

What you'll do

Choose how users sign in

Rank passkeys, 2FA, magic links and passwords, and decide whether to roll your own or use a provider.

Build a login you can read

Hash with Argon2id, issue server-side sessions, and add login, logout, forgot and reset routes that don't leak accounts.

Attack it with curl

Test enumeration, brute force and the reset path yourself, then enforce auth in one place.

  • Brute-force limits per IP and per account
  • Reset tokens stored hashed, single use
  • A ten-line checklist for any login, yours or a provider's
Before you start
  • Python 3.11+ and uv, plus curl (built into Windows 10+, Mac, Linux)
  • Basic familiarity with HTTP: what a POST, a cookie and a status code are
  • Optional: a Next.js or FastAPI app of your own to apply this to. The lab stands alone otherwise
  • The previous mission's login probe results, if you ran it
Your progress0/6
01/06What to use in 2026, in order, and why0 done
STEP 01 of 06~10 min

What to use in 2026, in order, and why

Decide the shape of your login before writing code. Most auth bugs are design choices made by default.

Before any code, start by looking at the options.

The ranking

Here's the ranking, best first. Pick the highest one your users will accept.

  • Passkeys (WebAuthn). No password to steal, phish, reuse or stuff. The private key never leaves the user's device; the site gets a signature bound to its own origin, so a lookalike domain gets nothing. Supported in every current browser and OS. The user-side setup is in lock down your accounts with passkeys. On the app side, don't implement WebAuthn yourself: use your auth provider's passkey option (Supabase, Clerk, Auth0 and Auth.js all have one) or a library like webauthn (Python) or @simplewebauthn/server (Node). Offer passkeys as the default sign-up path and keep a password or magic link as the fallback.
  • Password plus 2FA (TOTP or a security key). The password can still be phished, but a stuffed password alone no longer gets in. TOTP (authenticator app) is good; SMS is better than nothing but SIM swaps are real. Make 2FA mandatory for admin accounts and anyone who can see other users' data.
  • Magic links. An emailed one-time link. No password to store; security is now your users' inbox security. Fine for low-value apps and newsletters. Tokens must be single use, short-lived and stored hashed, exactly like reset tokens below.
  • Password alone. The floor. Acceptable for a small app if, and only if, the hash is Argon2id, guesses are rate-limited, and sign-up rejects passwords found in breaches (the Have I Been Pwned k-anonymity API does this with no key).

Should you roll your own?

Honest answer, by situation:

  • You're building on Supabase already: use Supabase Auth. It gives you passkeys, magic links, OAuth, rate limits and RLS integration, and the alternative is maintaining the same thing worse.
  • Next.js app, you want polished UI and org/team features fast: Clerk. Costs money past the free tier, but the sign-up, 2FA and session management are better than what you'd build in a month.
  • Next.js app, you want to own the data and avoid a vendor: Auth.js (NextAuth) with a database adapter and the Credentials or Passkey provider. More wiring than Clerk, no per-user fee.
  • FastAPI, Django, Rails, or anything server-rendered: your framework's built-in auth (Django's especially) or the pattern in this mission. Server-side sessions are simple here and the code below is complete.
  • Roll your own from scratch in a client-heavy app with JWTs: don't, unless you've read this whole mission and can say why you need a JWT.

You'll build the from-scratch version here even if you end up using a provider, because then you know what the provider is doing and can tell when it's configured wrong.

Checkpoint
You've written one line: which option from the first list, and which from the second, for your app, and why in ten words.
Stuck? Ask the community
Next mission · Protect your app and websiteTLS, the six headers, CORS and Cloudflare in front: what each setting actually blocks
→