A simple OTP Generation and Verification Library which works without a Database or Cache.
- Does not require database or cache
- Easy to implement
- Has OTP expiry function
Usage explained in diagram below
pip install -U simple-otp
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='[email protected]')
# 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'
- Make
- Python
- Twine
One time initialisation
make init
- 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
make deploy
Please find the changelog here: CHANGELOG.md
simple-otp was written by Kshitij Nagvekar.