OTPpy
OTP library for Python 3 : HOTP and TOTP ( RFC4226 & RFC6238 )
Easy to use OTP 2FA check and generator, counter-based or time-based
- Fully compatible with standards
- Can manage 4 to 8 digits
- Can manage SHA1, SHA256 or SHA512 hash functions (as in RFC6238)
Compatible with Google Authenticator (default settings)
Using library
Get the library
From pip/pypi repository :
python3 -m pip install otppy
Or the old fashion way :
Copy the otppy folder in your working directory.
Use
from otppy import OTP in your Python program.
Examples
Example for code generation :
from otppy import OTP
this_otp = OTP.fromb32("BASE32SECRETHERE")
# TOTP return : [TOTPcode, Remaining Time in seconds]
totp = this_otp.TOTP()
print("TOTP Code :", totp[0])
print(totp[1], "sec left")
Example for code check :
# Initialize
from otppy import OTP
this_otp = OTP.fromb32("BASE32SECRETHERE")
# Check validity, return a boolean
totp_valid = this_otp.check_TOTP(string_code_received)
Interface methods of OTPpy OTP
otppy.OTP( secret, hashalg="sha1", digits=6, time_window=30 )
Create an OTP object from a raw secret.
Better to use with the class constructor "fromb32" :
otppy.fromb32( secret_base32, hashalg="sha1", digits=6, time_window=30 )
Load an OTP from parameters, including the shared secret as base32 encoded.
secret_base32 is the shared secret encoded in base32, optional padding.
hashalg is the hash algorithm to use : "sha1", "sha256" or "sha512".
digits is the integer for number of digits.
time_window is the time width of a time block in seconds (integer).
Note that the secret_base32 argument is enough to use a standard OTP setting (sha1, 6 digits and 30 seconds blocks).
.HOTP( counter )
Compute a HOTP code from the integer counter value.
Return the HOTP code as a string.
.TOTP( )
Compute a TOTP code from the current UTC machine time.
Return a duet list : the TOTP code as a string, and the remaining validity time in seconds.
.check_HOTP( counter_value, hotp_string )
Check the HOTP code string for the given values.
Return a boolean.
.check_TOTP( totp_string )
Check the TOTP code string (for the machine UTC time).
Return a boolean.
Form more details: see otppy/ code.
Internal tests
Test vectors from standards included in tests directory for pytest :
python3 -m pytest tests
Licence
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Metadata
Release files for OTPpy 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| OTPpy-0.1.2.tar.gz | 16.5 kB | Without provenance | Details for OTPpy-0.1.2.tar.gz |
Release files / OTPpy-0.1.2.tar.gz
| Download URL | OTPpy-0.1.2.tar.gz |
|---|---|
| Size | 16.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
826a9dd3110b94d209f90b101594650420c10e2c99c27477533dce63031ec668
|
|
BLAKE2b-256 checksum How to use checksums |
72924cddfe9aba928b35728ff4f87a12e32aa89888225fecda7bbba609e926eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.5.0.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.8
|
Security for OTPpy 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.