A minimal, dependency-free implementation of TOTP (Time-Based One-Time Password) written in pure Python using only the standard library.
This script demonstrates how Google Authenticator works on the server side by implementing RFC 6238 manually.
- ✅ Generate secure random TOTP secrets
- ✅ Accept custom plain-text secrets (auto-converted to Base32)
- ✅ Generate
otpauth://URL compatible with Google Authenticator - ✅ Manual TOTP generation using:
- HMAC-SHA1
- 30-second time step
- Dynamic truncation
- ✅ Token verification with configurable clock drift window
- ✅ No third-party libraries required
- How TOTP works internally
- How servers verify Google Authenticator tokens
- How shared-secret + time-based OTP systems function
- RFC 6238 compliant implementation
- Run the script.
- Enter a custom secret or press Enter to auto-generate one.
- Scan the generated
otpauth://URL using Google Authenticator. - Enter the 6-digit code from the app to verify.
- Algorithm: HMAC-SHA1
- Digits: 6
- Period: 30 seconds
- Clock tolerance: ±1 time window (configurable)
- Always generate cryptographically secure random secrets.
- Store secrets encrypted at rest.
- Implement rate limiting for verification attempts.
Pure Python. Zero dependencies. Fully transparent TOTP implementation.