A simple TOTP generator package to help you in developing tools that require TOTP
Project description
T2fa - Simple and Easy-to-Use TOTP Generator
T2fa is a lightweight and easy-to-use Time-Based One-Time Password (TOTP) generator. This library is perfect for developers who need to integrate TOTP functionality into their tools, whether for authentication or security-related applications. With T2fa, you can easily generate TOTP tokens for use in requests-based tools, APIs, and many other applications that require secure one-time passwords.
Features
- Easy Integration: T2fa allows for simple integration with your Python projects.
- Multiple Algorithm Support: Supports SHA-1, SHA-256, and SHA-512 algorithms for TOTP generation.
- Flexible: Customize the number of digits and time intervals for OTP generation.
- Cross-Platform: Works on all major platforms where Python is supported.
- Secure: Implements TOTP as per RFC 6238, ensuring the highest level of security.
Installation
Using pip
You can easily install T2fa via pip, Python's package manager. Simply run the following command:
pip install T2fa
Manual Installation
-
Clone the repository:
git clone https://github.com/AxZeRxD/T2fa.git cd T2fa
-
Install dependencies:
pip install -r requirements.txt
-
(Optional) You can now manually run the tests or use the tool in your project.
Usage
Importing T2fa
To get started, you first need to import the Totp class from the package:
from T2fa import Totp
Example Usage
# Example of generating and verifying OTP
secret = "khxi okcj zqtc j54b 2t2x awcr xx3x g5ln" # Secret key used for TOTP generation
# Initialize the TOTP object for SHA-1 algorithm
pyauth_sha1 = Totp.gen(secret=secret, algorithm="SHA1", digits=6, interval=30)
# Generate OTP
otp_sha1 = pyauth_sha1.genotp()
print(f"Generated OTP (SHA1): {otp_sha1}")
# Verify OTP
if pyauth_sha1.verifyotp(otp_sha1):
print(f"OTP (SHA1) is valid.")
else:
print(f"OTP (SHA1) is invalid.")
Supported Algorithms
- SHA-1: Default algorithm for TOTP generation.
- SHA-256: A more secure option with a longer hash length.
- SHA-512: Provides even higher security and longer hash length.
You can switch between these algorithms using the algorithm parameter when creating a TOTP instance.
Configuration
You can configure various aspects of the OTP generation:
digits: Number of digits in the OTP (default is 6).interval: The time window for OTP validity in seconds (default is 30 seconds).algorithm: The hashing algorithm to use for OTP generation (options: "SHA1", "SHA256", "SHA512").
Example for Customization
# Custom configuration for SHA-256 with a 8-digit OTP and 60-second interval
pyauth_sha256 = Totp.gen(secret=secret, algorithm="SHA256", digits=8, interval=60)
otp_sha256 = pyauth_sha256.genotp()
print(f"Generated OTP (SHA256): {otp_sha256}")
Testing
You can run tests to ensure that everything works as expected. If you're using pytest or another test runner, you can run:
python pytest
Or simply run your Python script to check if TOTP generation and verification are working properly.
Contributing
We welcome contributions! If you have suggestions for improvements, please fork the repository and create a pull request.
- Fork the repository.
- Create a new branch for your changes.
- Commit your changes.
- Push your changes to your fork.
- Submit a pull request to the main repository.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- The TOTP implementation follows the RFC 6238 standard for time-based one-time passwords.
- This project was inspired by various TOTP libraries available in the Python ecosystem.
- Thanks to the open-source community for their valuable contributions!
For any additional questions or support, feel free to open an issue in the repository.
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 t2fa-0.1.0.tar.gz.
File metadata
- Download URL: t2fa-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8def7066a337f78ca19e00f5b0f5fb7090748f828d13589669403b2a8945abc1
|
|
| MD5 |
9b268e89db2df692f0fc709b27bfa11c
|
|
| BLAKE2b-256 |
88076ecccee97d6c66fb5d603c42617bd5b75e901f3039ba21f1cf0a7602728e
|
File details
Details for the file T2fa-0.1.0-py3-none-any.whl.
File metadata
- Download URL: T2fa-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81e5df5ced74bb0d6d547438e942f1326dc3685a833ea417d5559c1e1d00279e
|
|
| MD5 |
4436f481994994f2560ad47eabbc038c
|
|
| BLAKE2b-256 |
eabb671e659c031bb921f8fc8a55ca80ac60e1c30c208e7239977bf5981a1088
|