feat(auth): add single-use totp recovery codes
Codes are stored as SHA-256 hashes and consumed with one conditional update, so concurrent use of the same code succeeds at most once. Refs #40 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
3f21361995
commit
dbea42e7a5
9 files changed
+248
No files matched your search
@@ -0,0 +1,12 @@
|
||||
-- name: DeleteRecoveryCodes :exec
|
||||
DELETE FROM recovery_codes WHERE user_id = $1;
|
||||
|
||||
-- name: InsertRecoveryCodes :copyfrom
|
||||
INSERT INTO recovery_codes (user_id, code_hash) VALUES ($1, $2);
|
||||
|
||||
-- name: UseRecoveryCode :execrows
|
||||
UPDATE recovery_codes SET used_at = now()
|
||||
WHERE user_id = $1 AND code_hash = $2 AND used_at IS NULL;
|
||||
|
||||
-- name: CountUnusedRecoveryCodes :one
|
||||
SELECT count(*) FROM recovery_codes WHERE user_id = $1 AND used_at IS NULL;
|
||||
Reference in new issue
Block a user