Skip to main content

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:

  • --window-count, -w: Tokens in the previous 30s time windows that should be considered valid (default: 0)
  • --time-period, -t: OTP valid time period in seconds (default: 30)

Example:

  • Without window count or time period option
otp-cli-utils validate ABCDEF1234567890 123456
  • With window count option
otp-cli-utils validate ABCDEF1234567890 123456 --window-count 2
  • With time period option
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 successfully
  • 1: Invalid OTP (for validate command) or error occurred

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

otp_cli_utils-1.4.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

otp_cli_utils-1.4.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file otp_cli_utils-1.4.0.tar.gz.

File metadata

  • Download URL: otp_cli_utils-1.4.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for otp_cli_utils-1.4.0.tar.gz
Algorithm Hash digest
SHA256 a5f2a22a9b1e0951365c9e8ba1729e86a3a2f8e084df043b0bdb8eec1715139b
MD5 4a029e22b46fbc3a1424806608c32bff
BLAKE2b-256 fef6f8920239a20c235baf00bf7793ff1a3aa98132e6b8ed19ea48e54146bca6

See more details on using hashes here.

File details

Details for the file otp_cli_utils-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: otp_cli_utils-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for otp_cli_utils-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29036a92346c793c67ad6466e1913d9c627c4420baba652484d5ce3eb77abebc
MD5 7f7119526d12829732458c964209138c
BLAKE2b-256 001de5a17907eaa7d7043c37c500dfb5c398f910be553ec9d8423cee0ff9ed4a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page