-- Add last_totp_counter to track the most recently accepted TOTP counter value -- per account. This is used to prevent TOTP replay attacks within the ±1 -- time-step validity window. NULL means no TOTP code has ever been accepted -- for this account (fresh enrollment or TOTP not yet used). -- -- Security (CRIT-01): RFC 6238 §5.2 recommends recording the last OTP counter -- used and rejecting codes that do not advance it, eliminating the ~90-second -- replay window that would otherwise be exploitable. ALTER TABLE accounts ADD COLUMN last_totp_counter INTEGER DEFAULT NULL;