simple-otp
A simple OTP Generation and Verification Library which works without a Database or Cache.
Features
- Does not require database or cache
- Easy to implement
- Has OTP expiry function
How to use this?
Usage explained in diagram below
Installation
pip install -U simple-otp
Usage Example
import os
from time import sleep
from simpleotp import OTP
SECRET_KEY = os.getenv('SECRET')
otp_handler = OTP(SECRET_KEY,
length=6,
expires_after=2,
user_identifier='kshitij.nagvekar@workindia.in')
# generate OTP - returns OTP and hash
otp, sig = otp_handler.generate()
print(otp, sig)
# verify OTP - correct OTP and hash passed to verify method
is_verified = otp_handler.verify(otp, sig)
print(is_verified) # returns True
# verify OTP - incorrect hardcoded OTP passed to verify method
is_verified = otp_handler.verify('123', sig)
print(is_verified) # returns False
# Sleep added to simulate Expiry of OTP
sleep(2 * 61)
# Correct OTP and hash passed to verify method
# But after expiry time has passed
is_verified = otp_handler.verify(otp, sig)
print(is_verified) # returns False
The library also includes helper method to generate a random secret key
from simpleotp import generate_secret
SECRET_KEY = generate_secret()
print(SECRET_KEY) # 'Q0CZYBRDECESA72M'
Build Requirements
- Make
- Python
- Twine
Initialise Build Environment
One time initialisation
make init
Make a release build
- Ensure that working directory is clean and all files are commited.
- Bump the version. Please read Semantic Version 2.0.0 before bumping versions.
make release PART=[major/minor/patch] - Update the CHANGELOG.md.
- Push release tags.
git push origin --tags - Make a release build.
make dist
Publish your changes
make deploy
Changelog
Please find the changelog here: CHANGELOG.md
Authors
simple-otp was written by Kshitij Nagvekar.
Metadata
Release files for simple-otp 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| simple_otp-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Release files / simple_otp-0.1.1-py3-none-any.whl
| Download URL | simple_otp-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af428a0e52c6fa5f3143284edfbb7db5270c505025ce899f5a321a16b93e3b07
|
|
BLAKE2b-256 checksum How to use checksums |
c2c12f9de7eccd6f818850c2ccd897de6ae03e6596e283b1d79add1146c9b87b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.10
|