Auth Starter

Reference implementation

Authentication, done properly.

A complete, working user system: sign-up with verified email, revocable database-backed sessions, password reset, TOTP two-factor with recovery codes, Google sign-in, rate limiting and an audit trail. Every form works without JavaScript.

Create an accountSign in
Passwordsscrypt at OWASP parameters, per-password salt, constant-time comparison, optional server pepper, automatic rehash on login.
SessionsOpaque 256-bit tokens stored only as SHA-256 hashes. HttpOnly, __Host- prefixed in production, sliding expiry, revocable per device.
Email flowsVerification and reset links are single-use, time-limited and redeemed by POST so mail scanners cannot burn them.
Two-factorRFC 6238 TOTP implemented on node:crypto, replay-protected, with ten single-use recovery codes.
Abuse controlFixed-window rate limits per account and per IP, persisted in the database, plus account lockout.
Audit trailEvery sign-in, failure, reset and 2FA change is recorded and shown back to the account owner.

HTTP API

POST /api/auth/signup            POST /api/auth/2fa/setup
POST /api/auth/login             POST /api/auth/2fa/enable
POST /api/auth/logout            POST /api/auth/2fa/disable
POST /api/auth/logout-all        POST /api/auth/sessions/revoke
GET  /api/auth/session           GET  /api/auth/oauth/google/start
POST /api/auth/verify-email      GET  /api/auth/oauth/google/callback
POST /api/auth/forgot-password   POST /api/auth/reset-password
POST /api/auth/change-password   POST /api/auth/resend-verification

Send Accept: application/json for JSON in and out; plain form posts get a redirect back to the page with an error code.

This deployment

  • Database · managed MySQL, persistent
  • Email delivery · not configured — links print to the server log
  • Email confirmation · optional
  • Google sign-in · not configured
  • Two-factor · TOTP with recovery codes, available to every account