Add optional TOTP MFA (Two-Factor Authentication) support #84
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds optional QR code-based TOTP (Time-based One-Time Password) multi-factor authentication for lightNVR users.
Changes
Database
0021_add_totp_mfa.sql— Addstotp_secretandtotp_enabledcolumns to theuserstableBackend (C)
api_handlers_totp.c/.h) — RFC 6238 implementation using HMAC-SHA1 via mbedTLS, including base32 encoding/decoding, secret generation (160-bit), code generation (6-digit, 30s window), and verification with ±1 window tolerancePOST /api/auth/users/:id/totp/setup— Generate secret, returnotpauth://URIPOST /api/auth/users/:id/totp/verify— Verify code & enable TOTPPOST /api/auth/users/:id/totp/disable— Disable TOTPGET /api/auth/users/:id/totp/status— Check TOTP statusPOST /api/auth/login/totp— Second-step TOTP login verificationtotp_requiredresponse with a short-lived pending token (5 min TTL) instead of a session cookiedb_auth_get_totp_info(),db_auth_set_totp_secret(),db_auth_enable_totp()with backward compatibility viacached_column_exists()totp_enabledin SQL queries and zero-initializeuser_tstructs to prevent uninitialized memory from showing incorrect MFA statusFrontend (Preact/JSX)
LoginView.jsx) — After password success, shows TOTP code input with 6-digit field, back button, and auto-focusTotpSetupModal.jsx) — QR code display (viaqrcodenpm package), manual secret entry, verification code input, enable/disable functionalityUsersTable.jsx) — Added MFA status column and MFA management button in actionsUsersView.jsx) — Integrated TOTP modal with state managementDesign Decisions
cached_column_exists()throughout so databases without the migration still workPull Request opened by Augment Code with guidance from the PR author