A small Node.js server that implements Time-Based One-Time Password (TOTP) Multi-Factor Authentication (MFA) using the Authenticator app protocol.
- 🔐 Generate MFA secret keys
- 📱 QR code generation for easy Authenticator app setup
- ✅ Verify TOTP tokens
- 🌐 Simple web interface for testing
- 🔒 Compatible with Google Authenticator, Authy, Microsoft Authenticator, and other TOTP apps
- Clone this repository:
git clone https://github.com/arrival-space/MFA-Test-.git
cd MFA-Test-- Install dependencies:
npm install- Start the server:
npm start- Open your browser and navigate to:
http://localhost:3000
- Follow the on-screen instructions:
- Enter a username and generate an MFA secret
- Scan the QR code with your Authenticator app
- Enter the 6-digit code from your app to verify
POST /api/generate-secret
Request body:
{
"username": "your-username"
}Response:
{
"secret": "BASE32_ENCODED_SECRET",
"qrCode": "data:image/png;base64,...",
"otpauth_url": "otpauth://totp/..."
}POST /api/verify-token
Request body:
{
"username": "your-username",
"token": "123456"
}Response (success):
{
"success": true,
"message": "Token verified successfully!"
}GET /api/status/:username
Response:
{
"username": "your-username",
"hasSecret": true,
"verified": true
}GET /api/health
Response:
{
"status": "ok",
"message": "MFA Server is running"
}- express - Web framework for Node.js
- speakeasy - TOTP/HOTP library for two-factor authentication
- qrcode - QR code generation
- Store secrets securely in a database with encryption (currently stored in-memory)
- Use HTTPS for all connections to prevent secret interception
- Implement rate limiting on verification endpoints to prevent brute force attacks (Critical - not implemented in this demo)
- Add user authentication before MFA setup
- Implement proper session management
- Add backup codes for account recovery
- Never expose secrets in API responses after initial setup
- Follow security best practices for your specific use case
This demo application has the following security limitations that must be addressed before production use:
⚠️ No rate limiting - The/api/verify-tokenendpoint is vulnerable to brute force attacks⚠️ In-memory storage - Secrets are lost on restart and not encrypted⚠️ Secret exposure - The API returns the secret in responses (should only be shown once)⚠️ No authentication - Anyone can create/verify MFA secrets without authentication
- Secret Generation: Creates a unique base32-encoded secret key for each user
- QR Code: Generates a QR code containing the secret and app name
- TOTP Algorithm: Uses the Time-Based One-Time Password algorithm (RFC 6238)
- Verification: Validates 6-digit codes that change every 30 seconds
ISC