Django SOTP 🔐
Generate a secured base32 one time password to authenticate your user!
Abstract 📑
Django SOTP does just two things, and does them really well.
- One - it is stupidly secured and simple to integrate
- Two - it clears out OTPs at the elapsed time
Installation ⏳
Installing django-sotp is very easy, you'll be using (I'd recommend you use a virtual environment, so you don't break your system) the command pip.
Here's how to go about it:
pip install django-sotp
Next is, adding the installed packages to your project:
INSTALLED_APPS = [
...
'sotp',
]
Since django-sotp depends on a particular package to clear out the OTPs at the elapsed time. We'd have to include another package to our installed apps.
INSTALLED_APPS = [
...
'sotp',
'django_apscheduler', # added package ;-)
]
Now you've done it, all you need to do is add the time which you want the generated OTPs to expire:
SOTP_TIME_EXPIRATION = 5 # in minutes
Yesss. Next is to make migrations and migrate to your database and you're good to go!
python manage.py makemigrations && python manage.py migrate
Congratulations! You're all set! Let's jump right into how to start using it.
How-To Use 📝
You've got django-sotp installed and ready to use, here's how to start using it!
- Step 1: Import the library to the file
(.py)you want to use:
from sotp.services import GenerateSOTP
- Step 2: Instantiate the class:
otp = GenerateSOTP()
- Step 3: Call the
generate_otplogic (method) directly in the file, and pass the user's email; since generate_otp requires the user email address to generate the otp code.
# Generates otp code for the user
otp.generate_otp(user_email=user.email)
-
Step 4: A base32 secured token and code has been generated, and saved to the secured_otps table. Oh, let's not forget about the scheduler that has been called to remove the user otp and token after the
SOTP_TIME_EXPIRATIONhas elapsed! 🤝 -
Last Step (maybe?): You can call the function anywhere, anytime.
If you are still finding it difficult to use this package, kindly check the example app I made for reference, or create an issue and state the problem you are experiencing!
Shell Example 🥁
If you'd like to test out the package on your django shell..
- Step 1: Run the command:
python manage.py shell
- Step 2: Import the libray directly on the shell:
from sotp.services import GenerateSOTP
- Step 3: Call the generate_otp method, don't forget to add a user email address:
secured_otp = otp.generate_otp(user_email="test@email.com") # email should exist :-)
- Step 4: A Token and OTP is generated, and saved to secured_otps database.
{'totp': '5ZCLA7UQVXFP2B5WL5OZG4QDFDJ4GL65', 'OTP': '957092'}
Metadata
Release files for django-sotp 1.0.4
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 | |
|---|---|---|---|---|
| django_sotp-1.0.4.tar.gz | 13.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_sotp-1.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.6 kB
Release files / django_sotp-1.0.4.tar.gz
| Download URL | django_sotp-1.0.4.tar.gz |
|---|---|
| Size | 13.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
394b6b965150f2e88d21b50b0135050442842b03ae01eec3ee80924f03a2cafa
|
|
BLAKE2b-256 checksum How to use checksums |
c10699a1fcd51c0b2084006ac1c8be417629482576ef296842f896668943e50d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.14
|
Release files / django_sotp-1.0.4-py3-none-any.whl
| Download URL | django_sotp-1.0.4-py3-none-any.whl |
|---|---|
| Size | 17.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f367645b20bd563d4d1e35282e4a4ae1f03b3497da42f6bda92bcf556f90efe
|
|
BLAKE2b-256 checksum How to use checksums |
ccc7172a45c8d1c30bf89dc3c602ec861e5d1591b490c27256e1ab055e241b7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.14
|
Security for django-sotp 1.0.4
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.