No description
Find a file
2024-10-08 17:49:14 +09:00
src update email verification 2024-10-08 17:49:14 +09:00
static init 2024-10-03 18:50:34 +09:00
.env.example init 2024-10-03 18:50:34 +09:00
.gitignore init 2024-10-03 18:50:34 +09:00
.npmrc init 2024-10-03 18:50:34 +09:00
.prettierignore init 2024-10-03 18:50:34 +09:00
.prettierrc init 2024-10-03 18:50:34 +09:00
LICENSE add license 2024-10-04 21:26:57 +09:00
package.json init 2024-10-03 18:50:34 +09:00
pnpm-lock.yaml init 2024-10-03 18:50:34 +09:00
README.md update readme 2024-10-06 16:35:13 +09:00
setup.sql update sql 2024-10-04 10:28:58 +09:00
svelte.config.js init 2024-10-03 18:50:34 +09:00
tsconfig.json init 2024-10-03 18:50:34 +09:00
vite.config.ts init 2024-10-03 18:50:34 +09:00

Email and password example with 2FA and WebAuthn in SvelteKit

Built with SQLite.

  • Password checks with HaveIBeenPwned
  • Sign in with passkeys
  • Email verification
  • 2FA with TOTP
  • 2FA recovery codes
  • 2FA with passkeys and security keys
  • Password reset with 2FA
  • Login throttling and rate limiting

Emails are just logged to the console. Rate limiting is implemented using JavaScript Map.

Initialize project

Create sqlite.db and run setup.sql.

sqlite3 sqlite.db

Create a .env file. Generate a 128 bit (16 byte) string, base64 encode it, and set it as ENCRYPTION_KEY.

ENCRYPTION_KEY="L9pmqRJnO1ZJSQ2svbHuBA=="

You can use OpenSSL to quickly generate a secure key.

openssl rand --base64 16

Install dependencies and run the application:

pnpm i
pnpm dev

Notes

  • We do not consider user enumeration to be a real vulnerability so please don't open issues on it. If you really need to prevent it, just don't use emails.
  • This example does not handle unexpected errors gracefully.
  • There are some major code duplications (specifically for 2FA) to keep the codebase simple.
  • TODO: Passkeys will only work when hosted on localhost:5173. Update the host and origin values before deploying.
  • TODO: You may need to rewrite some queries and use transactions to avoid race conditions when using MySQL, Postgres, etc.
  • TODO: This project relies on the X-Forwarded-For header for getting the client's IP address.
  • TODO: Logging should be implemented.