This is a Python package to cater to all your needs for generating and verifying OTP (One-Time Password). You can use this package to enable 2FA (2-Factor Authentication) to safeguard your web applications.
The package currently only supports TOTP (Time-based One-Time Password) according to the specifications in RFC 6238 and will support HOTP (HMAC-based One-Time Password) which is based on RFC 4226 soon. The package will also add support for generating the QR code for key URI in future releases.
This is a server-side implementation of the TOTP. For the client-side, the user can use any authentication applications (e.g. Google Authenticator, Authy, etc.).
The package only supports Python 3.7 and above. To install:
pip install otpy
Alternatively,
python3 -m pip install otpy
To upgrade the package:
python3 -m pip install --no-cache-dir --upgrade otpy
Optionally, if you are Under unix, you can install the qrencode
package:
apt-get install qrencode
To verify that you have successfully installed the package, you can try to run (You must have qrencode
installed to run this):
python3 -m otpy
You will expect something like this:
This package is very simple to use. First, import the package:
from otpy import OTPY
First, instantiate a TOTP object:
key = "0123456789ABCDEF" # Key string must be hexadecimal!
otp = OTPY(key)
To get the Base32 encoded key value that is specified in RFC 3548, simply run:
otp.get_base32_key()
This value is compatible with apps like Google Authenticator and can be used to generate key URI.
To get the TOTP value:
otp.get_totp()
Lastly, to verify if an OTP is correct, run:
otp.verify_otp("123456")