This is a simple Python tool for generating and verifying TOTP-based two-factor authentication (2FA) codes using the
pyotp library.
- Python 100%
| .gitignore | ||
| LICENSE | ||
| python-totp-auth.py | ||
| README.de.md | ||
| README.md | ||
| requirements.txt | ||
Python TOTP 2FA Tool
This is a simple Python demo tool for generating and verifying TOTP-based two-factor authentication (2FA) codes with pyotp.
It allows you to:
- Generate a new shared secret (16 characters)
- Display the current 6-digit TOTP code
- Test a user-entered 2FA code against the generated or provided shared secret
Features
- Random shared secret generation
- TOTP code generation (6-digit PIN)
- Verification of user input against the current TOTP code
Requirements
- Python 3.6+
pyotppackage
Install dependencies with:
pip install -r requirements.txt
Usage
Run the script:
python python-totp-auth.py
Start file: python-totp-auth.py.
You will be prompted to either:
- Generate a new shared secret (which will immediately display a valid TOTP code)
- Test an existing shared secret by entering it manually and verifying a TOTP code
Example
Would you like to generate a new shared secret or test an existing one? (1 = generate, 2 = test): 1
Randomly generated shared secret (16 characters): Xk8T2...
Your current TOTP code is: 123456
Notes
- TOTP codes change every 30 seconds.
- Treat this as a learning/demo script.
- For real use, store secrets securely and do not print them unnecessarily.
- A practical next step would be QR code generation for authenticator apps.
License
MIT - feel free to use and modify.