This is a simple Python tool for generating and verifying TOTP-based two-factor authentication (2FA) codes using the pyotp library.
Find a file
2026-05-05 10:54:29 +02:00
.gitignore Standardize Python project setup 2026-05-05 10:54:29 +02:00
LICENSE Initial Commit 2025-04-09 13:50:49 +02:00
python-totp-auth.py Initial Commit 2025-04-09 13:47:40 +02:00
README.de.md Standardize Python project setup 2026-05-05 10:54:29 +02:00
README.md Standardize Python project setup 2026-05-05 10:54:29 +02:00
requirements.txt Initial Commit 2025-04-09 13:47:40 +02:00

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+
  • pyotp package

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:

  1. Generate a new shared secret (which will immediately display a valid TOTP code)
  2. 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.