Login and MFA
Covers the login flow, password policy, second-factor verification and password recovery.
Login flow
- Submit username and password, with an optional captcha
- The server verifies the password and lock state, then issues access and refresh tokens
- Accounts with MFA enabled must complete a second factor before tokens become valid
- Refresh tokens rotate: each refresh revokes the old token

Password policy
| Setting | Default | Description |
|---|---|---|
| Minimum length | From security config | 12+ recommended in production |
| Complexity | Upper, lower, digit, symbol | Changes are rejected if the policy fails |
| Failure lock | Threshold-based | Login is refused while locked |
MFA verification
When enabled, step one returns a challenge instead of tokens. After the user submits a TOTP code, the server atomically consumes the challenge and issues tokens.
- TOTP secrets are encrypted at rest, with legacy plaintext still readable
- Challenge consumption is serialized with a cache lock to prevent replay
- Disabling MFA requires password re-verification
Password recovery
- The user submits a registered email. The API always returns the same generic success body to avoid account enumeration.
- The token is persisted first, and the delivery job is enqueued to the
emailsqueue. - worker sends the mail. Failures land in the failed job table for manual replay.
- The reset link is single-use.
WARNING
Keep SECURITY_RESET_DEV_RETURN_TOKEN=false in production. Plaintext token echo is only for local environments without SMTP.
