A Python CLI tool to validate OTP codes
Project description
OTP CLI Utils
A command-line utility for working with TOTP (Time-based One-Time Password) codes. This tool helps you generate, validate, and manage OTP secrets with ease.
Features
- 🔑 Generate current TOTP codes from a secret
- ✅ Validate OTP codes against a secret
- 🔄 Generate secure random OTP secrets
- 📱 Create Google Authenticator compatible QR codes
- 🛠️ Simple and intuitive command-line interface
Installation
Install the package using pip:
pip install otp-cli-utils
Usage
Get Current OTP Code
Get the current OTP code for a given secret:
otp-cli-utils get-otp <secret>
Example:
otp-cli-utils get-otp ABCDEF1234567890
Validate an OTP
Validate if an OTP code matches the expected value for a given secret:
otp-cli-utils validate <secret> <otp> [--window-count <count> | --time-period <seconds>]
Options (mutually exclusive - use only one):
--window-count,-w: Number of time steps to validate against (default: 0)--time-period,-t: Time period in seconds to validate against (must be ≥30 and a multiple of 30)
Examples:
- Basic validation (checks current time step only):
otp-cli-utils validate ABCDEF1234567890 123456
- With window count (checks current and previous N time steps):
otp-cli-utils validate ABCDEF1234567890 123456 --window-count 2
- With custom time period (in seconds, must be multiple of 30):
otp-cli-utils validate ABCDEF1234567890 123456 --time-period 120
Generate a New OTP Secret
Generate a new secure random secret key for OTP generation:
otp-cli-utils generate-secret
Generate QR Code for Authenticator Apps
- Generate a QR code that can be scanned by Google Authenticator or similar apps
- QR code will be generated with a new secure random secret key
- Generated QR code will be saved as a png image file
otp-cli-utils generate-secret-qr-code <label> <issuer> [filename]
Arguments:
label: Account name (e.g., user@example.com)issuer: Service or provider name (e.g., GitHub)filename: (Optional) Output filename without extension (default: otp_secret_qr)
Example:
otp-cli-utils generate-secret-qr-code "user@example.com" "GitHub" github_2fa
Exit Codes
0: Command executed successfully1: Invalid OTP (for validate command) or error occurred
Input Validation
The tool performs the following validations on the inputs:
-
OTP Secret:
- Must be a valid Base32 encoded string.
- The length of the secret must be a multiple of 8.
- It can only contain uppercase letters (
A-Z), digits from2to7, and the padding character (=).
-
OTP Code:
- Must be a 6-digit number.
-
Window Count (
--window-count,-w):- Must be an integer.
- Must be a non-negative number (0 or greater).
-
Time Period (
--time-period,-t):- Must be an integer.
- Must be 30 seconds or greater.
- Must be a multiple of 30.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file otp_cli_utils-1.5.1.tar.gz.
File metadata
- Download URL: otp_cli_utils-1.5.1.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e20c622e6f3787f91cdad27cc8c112b0710e17334e9bdc297eb4f1f109ef9a2b
|
|
| MD5 |
9e39a0c63704a15166c3fcae62cb107a
|
|
| BLAKE2b-256 |
a6081193a1b6247a3b520f3c4fcf5d17d70320c06d80221860d08ecc40f6d443
|
File details
Details for the file otp_cli_utils-1.5.1-py3-none-any.whl.
File metadata
- Download URL: otp_cli_utils-1.5.1-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84a4977eba3ffdda5939dc21f106898c2ffd558dc993066c32ebabed597c92bb
|
|
| MD5 |
72328963db2905ecf6f193e2c004a62b
|
|
| BLAKE2b-256 |
779b041d81a0bedc4a318392ffc403ab7b7feba454349fdc566e0fe1b3003bb0
|