Two-Factor Authentication for Django Admin with TOTP, backup codes, trusted devices, and more.
Project description
Django Admin 2FA Plus
Django Admin 2FA Plus is a secure, easy-to-use Two-Factor Authentication package for Django Admin. It provides TOTP-based verification (Google Authenticator, Authy, etc.), recovery codes, and optional trusted devices.
🌟 Features
- 🔐 Secure Django Admin with 2FA
- 📱 TOTP Authentication (Google Authenticator, Authy, 1Password, etc.)
- 🔑 One-time use Backup Recovery Codes
- 📩 Optional Email OTP fallback (configurable)
- 🧩 Admin interface to manage TOTP Devices
- 🎛️ Trusted Device support (via cookies)
- 🎨 Customizable templates
- ⚙️ Middleware-based enforcement
- ⚡ Works with Django 3.2+
📦 Installation
pip install django-admin-2fa-plus
Add it to your INSTALLED_APPS:
INSTALLED_APPS = [
...
"django_admin_2fa_plus",
]
Add the middleware near the top of your middleware stack:
MIDDLEWARE = [
"django_admin_2fa_plus.middleware.Admin2FAMiddleware",
...
]
Include the URLs:
# urls.py
path("admin-2fa/", include("django_admin_2fa_plus.urls")),
Run migrations:
python manage.py migrate
🚀 Quick Start
- Log in to Django Admin.
- Go to
/admin-2fa/setup/to begin TOTP setup. - Scan the QR code using your authenticator app.
- Enter the generated code to confirm.
- Save the backup codes displayed — each can be used once.
- Done! 2FA is now required to access the admin area.
⚙️ Optional Settings
You can override the default behavior using these settings in your Django settings.py:
| Setting | Default | Description |
|---|---|---|
ADMIN_2FA_REDIRECT_URL |
/admin/ |
URL to redirect to after successful verification |
ADMIN_2FA_TOTP_DIGITS |
6 |
Number of digits for the TOTP code |
ADMIN_2FA_TOTP_STEP |
30 |
Step size in seconds for TOTP code rotation |
ADMIN_2FA_TOTP_ALGORITHM |
'sha1' |
Algorithm used for TOTP ('sha1', 'sha256', 'sha512') |
ADMIN_2FA_BACKUP_CODES_COUNT |
10 |
Number of backup codes generated |
ADMIN_2FA_TRUSTED_DEVICE_DAYS |
30 |
Days to trust a device when user selects "Remember this device" |
ADMIN_2FA_ENABLE_EMAIL_OTP |
False |
Enable fallback email OTP support |
ADMIN_2FA_EMAIL_SENDER |
None |
Sender address for email OTP |
ADMIN_2FA_EMAIL_SUBJECT |
'Your login code' |
Subject line for email OTP |
ADMIN_2FA_EMAIL_TEMPLATE |
None |
Path to custom HTML template for email OTP |
🧪 Testing
Unit test are pending
🤝 Contributing
Contributions are welcome! To contribute:
- Fork the repository
- Create your feature branch:
git checkout -b feature/my-feature - Commit your changes:
git commit -am 'Add new feature' - Update code, if needed, as per pre-commit logs
- Push to the branch:
git push origin feature/my-feature - Open a Pull Request
Please follow PEP8, isort and write tests for any new functionality.
📬 Support
For questions, bug reports, or feature requests, please open an issue on GitHub.
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.
Secure your Django Admin with ease ✨
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file dj_admin_2fa-0.0.2.tar.gz.
File metadata
- Download URL: dj_admin_2fa-0.0.2.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d1f810b7a632e8d127c9e17b1db1abf84613b1b7783af5934cb51aac5f0adb9
|
|
| MD5 |
79182fda2c91fb94b5da29c68fd85191
|
|
| BLAKE2b-256 |
ca03f3a0dcda93399a813ad7eef2ab778db24f01a274b2d0af5c237db3ef5b42
|