Phase 10, part 3: signing in and out, resets, locks and two-factor

The server edition now starts. Sign-in by email and password, limited per
address and per IP; ten failures in a row lock the account and email its
owner, and a reset by email (or an admin) unlocks it. Settings → Your
account has the profile, the password, where you're signed in, and
two-factor sign-in with an authenticator app (TOTP, from a QR code) and
ten recovery codes. The app's own mail goes through SUPERMARKET_MAIL_URL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 09:01:29 -07:00
co-authored by Claude Opus 5.5
parent 72455438c9
commit 8040512a18
26 changed files with 1991 additions and 12 deletions
+16
View File
@@ -104,6 +104,22 @@ CREATE TABLE links (
expires_at TEXT NOT NULL
);
CREATE INDEX links_user ON links(user_id, purpose);
`,
},
// 34
{
Note: "signing in: failed attempts and locks, two-factor sign-in, and limits on tries",
SQLite: `
ALTER TABLE users ADD COLUMN failed_signins INTEGER NOT NULL DEFAULT 0; -- in a row, since the last sign-in
ALTER TABLE users ADD COLUMN locked_at TEXT NOT NULL DEFAULT ''; -- locked after too many; '' when not
ALTER TABLE users ADD COLUMN two_factor INTEGER NOT NULL DEFAULT 0; -- an authenticator app is on (its secret is in secrets, totp:<id>)
ALTER TABLE users ADD COLUMN totp_step INTEGER NOT NULL DEFAULT 0; -- the last code's time step: each code works once
ALTER TABLE users ADD COLUMN recovery_codes TEXT NOT NULL DEFAULT '[]'; -- SHA-256s of the unused recovery codes
CREATE TABLE throttle (
key TEXT PRIMARY KEY, -- what's counted, e.g. signin:ip:203.0.113.5
count INTEGER NOT NULL DEFAULT 0,
since TEXT NOT NULL -- when the count started
);
`,
},
}