Skip to content

PrzemekSkw/totp-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

42 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“– About

...

TOTP Sync Logo

TOTP Sync

Self-hosted two-factor authentication (2FA) app with web interface and cross-device synchronization.

Beta Status Version

GitHub stars License


πŸ“Ί Live Demo

demo.webm

live demo: login β†’ dashboard β†’ add token


πŸ“Έ Screenshots

Dashboard with TOTP codes Dark mode support

Login page 2FA Setup with QR code


✨ Features

πŸ” Security & Authentication

  • Secure TOTP generation - Compatible with Google Authenticator, Authy, 1Password, etc.
  • End-to-end encryption - TOTP secrets encrypted with AES-256
  • WebAuthn/Passkey support - Passwordless login with biometrics (Touch ID, Face ID, Windows Hello)
  • Security key authentication - YubiKey, Titan, and other FIDO2 hardware keys
  • Cross-device authentication - Scan QR code with phone to login from desktop
  • Mandatory 2FA - Optional account protection during registration
  • Backup codes - 10 emergency codes per account for recovery
  • JWT authentication - Secure 30-day session tokens
  • Registration control - Enable/disable new user signups

πŸ”‘ WebAuthn Features

  • Passwordless login - Use biometrics or security keys instead of passwords
  • Multiple authenticators - Register YubiKey, Touch ID, Android biometrics simultaneously
  • Cross-platform support - Works on desktop, mobile, and hardware keys
  • Platform authenticators - Touch ID (Mac/iOS), Face ID (iOS), Windows Hello
  • Roaming authenticators - YubiKey, Google Titan, USB security keys
  • QR code authentication - Scan with phone to authenticate on desktop
  • Security key management - Add, rename, and remove keys in Settings

πŸ” Search & Organization

  • Live search - Instant filtering as you type
  • Multi-field search - Find by account name or issuer/app name
  • Result counter - Shows "X of Y" matches
  • Expandable search bar - Smooth animations in navbar
  • Perfect for 100+ entries - Fast client-side filtering

🎨 User Interface

  • Modern design - Clean, intuitive interface
  • Dark mode - Automatic or manual theme switching
  • Responsive layout - Works on desktop, tablet, and mobile browsers
  • Progress indicators - Visual countdown for code expiration
  • Hide codes - Optional privacy mode (auto-hide after 10 seconds)
  • Bulk operations - Select and delete multiple entries

πŸ“‹ Import & Export

  • JSON format - Standard TOTP export compatible with most apps
  • otpauth URI - Import from Google Authenticator, Authy, FreeOTP+, 2FAuth
  • Bulk import - Add multiple accounts at once
  • Replace or merge - Choose how to handle existing entries

πŸ”„ Synchronization

  • Cross-device sync - Access codes from any device via web browser
  • Self-hosted backend - Full control over your data
  • PostgreSQL or SQLite - Choose your preferred database

οΏ½οΏ½ Deployment

  • Docker Compose - One-command deployment
  • Easy updates - Pull and rebuild without data loss
  • Environment variables - Simple configuration
  • Reverse proxy ready - Works with Nginx, Caddy, Traefik

πŸ—„οΈ Database Options

TOTP Sync supports two database backends - choose based on your needs:

PostgreSQL (Default)

Best for: Multi-user deployments, production environments, high availability

DATABASE_TYPE=postgresql
POSTGRES_DB=totp_sync
POSTGRES_USER=totp_user
POSTGRES_PASSWORD=your_secure_password
DATABASE_URL=postgresql://totp_user:your_password@postgres:5432/totp_sync

Features:

  • βœ… Full ACID compliance
  • βœ… Concurrent user support
  • βœ… Advanced querying capabilities
  • βœ… Battle-tested for production

SQLite

Best for: Personal use, simple deployments, single-user setups

DATABASE_TYPE=sqlite
SQLITE_PATH=/data/totp-sync.db

Features:

  • βœ… Zero configuration
  • βœ… Single file database
  • βœ… Perfect for home labs
  • βœ… Easy backups (just copy the file)

Switching Databases

Simply change DATABASE_TYPE in your .env file and restart:

docker compose down
docker compose up -d

Note: Data is not automatically migrated between databases. Export your entries before switching.

πŸš€ Quick Start

Prerequisites

  • Docker & Docker Compose
  • Git

Installation

  1. Clone the repository:
git clone https://github.com/PrzemekSkw/totp-sync.git
cd totp-sync
  1. Create environment file:
cp .env.example .env
  1. Generate secure secrets:
# JWT Secret (copy the output)
openssl rand -base64 32

# Encryption Key (copy the output)
openssl rand -hex 16
  1. Edit .env file:
nano .env

Replace the following values:

  • POSTGRES_PASSWORD: Set a strong database password
  • JWT_SECRET: Paste the JWT secret from step 3
  • ENCRYPTION_KEY: Paste the encryption key from step 3 (must be exactly 32 characters)
  • DATABASE_URL: Update with the same password as POSTGRES_PASSWORD

Example:

POSTGRES_PASSWORD=my_secure_password_here
JWT_SECRET=1NRBJQja1Q1qjOw7LRXu2hDvm74HA5GbRWJ3yaL9GqM=
ENCRYPTION_KEY=91797e61a84e73c9dd5f78161f568ae4
DATABASE_URL=postgresql://totp:my_secure_password_here@postgres:5432/totp

Optional WebAuthn configuration (for passwordless login):

RP_NAME="TOTP Sync"
RP_ID="yourdomain.com"
ORIGIN="https://yourdomain.com"

Note: WebAuthn requires HTTPS in production. Use localhost for local testing.

  1. Start the application:
docker compose up -d
  1. Access the application:

Open http://localhost:5173 in your browser

Important Notes:

  • The .env file is ignored by git and won't be overwritten during updates
  • Always backup your .env file before major updates
  • Keep your secrets secure and never commit them to version control
  • WebAuthn requires HTTPS in production (except localhost)

πŸ“¦ Updating

To update to the latest version:

git pull
docker compose down
docker compose up -d --build

Your .env file and database will be preserved during updates.

βš™οΈ Configuration

Environment Variables

Backend configuration in docker-compose.yml:

Variable Description Default Required
REQUIRE_2FA_ON_REGISTER Force 2FA setup during registration "true" No
ALLOW_REGISTRATION Enable/disable new user registration "true" No
JWT_SECRET Secret for JWT token signing - Yes
ENCRYPTION_KEY Key for encrypting TOTP secrets (must be 32 chars) - Yes
POSTGRES_PASSWORD Database password - Yes
DATABASE_URL PostgreSQL connection string - Yes
RP_NAME WebAuthn relying party name "TOTP Sync" No
RP_ID WebAuthn relying party ID (your domain) "localhost" No
ORIGIN WebAuthn origin (full URL with protocol) "http://localhost:5173" No

WebAuthn Configuration

For passwordless authentication to work properly:

Local Development:

RP_ID="localhost"
ORIGIN="http://localhost:5173"

Production:

RP_ID="yourdomain.com"
ORIGIN="https://yourdomain.com"

Important:

  • RP_ID must match your domain (without protocol or port)
  • ORIGIN must be the full URL users access
  • HTTPS is required in production (localhost works with HTTP)
  • Create .well-known/webauthn file for domain verification

Ports

  • 5173 - Web interface
  • 3000 - Backend API

Configuring 2FA Behavior

Mandatory 2FA (default):

REQUIRE_2FA_ON_REGISTER: "true"

Users must set up 2FA during registration with QR code and backup codes.

Optional 2FA:

REQUIRE_2FA_ON_REGISTER: "false"

Users can enable 2FA later in Settings.

Controlling User Registration

Open Registration (default):

ALLOW_REGISTRATION: "true"

Anyone can create a new account.

Closed Registration:

ALLOW_REGISTRATION: "false"

New user registration is disabled. Only existing users can login.

πŸ”’ Security Notes

⚠️ Important Security Considerations:

  1. Always change default passwords - Generate strong, unique passwords
  2. Generate new secrets - Never use example secrets in production
  3. Use HTTPS in production - Required for WebAuthn, recommended for all traffic
  4. Store backup codes safely - Save them in a secure password manager
  5. Regular backups - Back up the PostgreSQL volume regularly
  6. Keep updated - Pull latest changes and rebuild regularly
  7. WebAuthn best practices - Register multiple authenticators (YubiKey + biometrics)

Production Deployment

For production use:

  • Use a reverse proxy with SSL/TLS certificates
  • Configure WebAuthn with your domain
  • Change default ports
  • Use Docker secrets for sensitive values
  • Set up monitoring and logging
  • Regular security updates
  • Consider disabling registration after initial setup

πŸ” 2FA Features

Registration with 2FA

  • Scan QR code with any authenticator app
  • Receive 10 backup codes for emergency access
  • Verify setup with 6-digit code before account creation

Login with 2FA

  • Enter email and password
  • Automatically prompted for 2FA code when enabled
  • Use backup codes if authenticator unavailable

Login with WebAuthn/Passkeys

  • Platform authenticators: Touch ID, Face ID, Windows Hello
  • Roaming authenticators: YubiKey, Google Titan, USB keys
  • Cross-device: Scan QR code with phone to login from desktop
  • No passwords needed: Completely passwordless authentication

Managing 2FA

  • Enable/disable 2FA in Settings
  • Generate new backup codes
  • Requires password + current 2FA code to disable

Managing Security Keys

  • Add multiple authenticators (YubiKey, Touch ID, phone)
  • Name your keys for easy identification
  • Remove keys you no longer use
  • See last used date for each key

πŸ“± Import/Export

Supported Formats

  • JSON - Standard TOTP export format
  • otpauth URI - Compatible with Google Authenticator, Authy, FreeOTP+, etc.

Importing from other apps

  1. Export from your current 2FA app (Google Authenticator, Authy, FreeOTP+, 2FAuth, etc.)
  2. In TOTP Sync, click "Import"
  3. Select your export file or paste URIs
  4. Choose "Replace All" or "Merge" with existing entries
  5. Your entries will be encrypted and synced

πŸ› Troubleshooting

Application won't start

Check logs:

docker compose logs -f

Database connection issues

Ensure PostgreSQL is healthy:

docker compose ps

Can't login after enabling 2FA

  1. Use one of your backup codes instead of TOTP code
  2. If no backup codes, you'll need to reset the database
  3. Always save backup codes in a safe place!

WebAuthn not working

  1. Check HTTPS: WebAuthn requires HTTPS (except localhost)
  2. Verify RP_ID: Must match your domain exactly
  3. Check browser support: Use Chrome, Firefox, Safari, or Edge (latest versions)
  4. Clear browser data: Sometimes cached credentials cause issues
  5. Check .well-known/webauthn: File must be accessible and return JSON

Security key not recognized

  1. Ensure key is FIDO2/WebAuthn compatible
  2. Try a different USB port
  3. Update key firmware if available
  4. Check browser permissions

Clear cache issues

  1. Clear browser cache and localStorage
  2. Try incognito/private browsing mode
  3. Check browser console for errors (F12)

πŸ› οΈ Development

Project Structure

totp-sync/
β”œβ”€β”€ backend/          # Node.js + Express API
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ routes/   # API endpoints
β”‚   β”‚   β”œβ”€β”€ services/ # Business logic
β”‚   β”‚   └── middleware/ # Auth & validation
β”‚   └── Dockerfile
β”œβ”€β”€ web/              # React + Vite frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/ # React components
β”‚   β”‚   β”œβ”€β”€ pages/      # Page views
β”‚   β”‚   β”œβ”€β”€ services/   # API client
β”‚   β”‚   └── store/      # State management
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   └── .well-known/webauthn  # WebAuthn domain verification
β”‚   └── Dockerfile
└── docker-compose.yml

Running in development mode

# Backend
cd backend
npm install
npm run dev

# Frontend
cd web
npm install
npm run dev

πŸ“ Changelog

v0.5.0-beta (Latest)

  • ✨ WebAuthn/Passkey support - Passwordless login with biometrics and security keys
  • ✨ Cross-device authentication - Scan QR code with phone to login from desktop
  • ✨ Security key management - Add/remove YubiKey, Touch ID, Windows Hello in Settings
  • ✨ Registration control - ALLOW_REGISTRATION environment variable
  • πŸ”’ Enhanced security - FIDO2/WebAuthn standard support
  • πŸ“± Platform authenticators - Touch ID, Face ID, Windows Hello, Android biometrics
  • πŸ”‘ Roaming authenticators - YubiKey, Google Titan, USB security keys
  • 🌐 .well-known/webauthn - Domain verification support
  • πŸ“š Updated documentation - WebAuthn setup guide and troubleshooting

v0.4.0-beta

  • πŸ”’ Security upgrade - Migrated to Node.js native crypto module
  • πŸ” AES-256-GCM encryption - Upgraded from AES-256-CBC with authentication
  • πŸ—„οΈ SQLite support - Choose between PostgreSQL and SQLite
  • 🐳 Node.js 20 - Updated runtime for better performance
  • βœ… Zero vulnerabilities - Clean npm security audit
  • ⚠️ Breaking change - Encryption system overhaul (migration required)

v0.3.0-beta

  • βœ… Added search functionality - Live filtering by account name and issuer
  • βœ… Expandable search bar - Smooth animations with auto-focus
  • βœ… Result counter - Shows "X of Y" matches when searching
  • βœ… Empty state - Clear messaging when no results found
  • βœ… Performance - Fast client-side filtering for 100+ entries

v0.2.0-beta

  • βœ… Fixed 2FA login functionality - Now working correctly
  • βœ… Fixed registration with 2FA - Proper pendingData handling
  • βœ… Improved UI - Removed unnecessary icons, added custom branding
  • βœ… Better error handling - Clear error messages and validation

v0.1.0-alpha

  • Initial release
  • Basic TOTP generation
  • Docker setup

🎯 Roadmap

v1.0.0 (Planned)

  • πŸ“± Mobile app - Native iOS and Android applications
  • πŸ”„ Push notifications - Real-time sync alerts
  • 🌍 Multi-language support - Internationalization
  • πŸ“Š Usage statistics - Analytics dashboard
  • πŸ” Advanced security - Rate limiting, IP whitelisting

Future Features

  • πŸ“‚ Folders/Categories - Organize TOTP entries
  • 🏷️ Tags - Label and filter entries
  • πŸ” Advanced search - Regex and filters
  • πŸ“€ Auto-backup - Scheduled exports
  • 🎨 Themes - Custom color schemes

πŸ“„ License

MIT License - feel free to use this project for personal or commercial purposes.

🀝 Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ’– Support

If you find this project useful, you can support its development:

Support via BuyMeCoffe:

Buy Me A Coffee

Support via PayPal:

PayPal

Support via Github Sponsors:

GitHub Sponsors

Your support helps maintain and improve this project. Thank you! ❀️

⭐ Star on Github

If you find this project useful, please consider giving it a star on GitHub!

Star History Chart


Made with ❀️ by PrzemekSkw

Secure your accounts with self-hosted 2FA

About

Self-hosted 2FA TOTP app with web interface and mobile sync

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages