Two-Factor Authentication for Django Admin with TOTP, backup codes, trusted devices, and more.
Project description
Dj Admin 2FA
**Dj Admin 2FA ** 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 dj-admin-2fa
Add it to your INSTALLED_APPS:
INSTALLED_APPS = [
...
"dj_admin_2fa",
]
Add the middleware near the top of your middleware stack:
MIDDLEWARE = [
"dj_admin_2fa.middleware.Admin2FAMiddleware",
...
]
Include the URLs:
# urls.py
path("admin-2fa/", include("dj_admin_2fa.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:
Admin 2FA settings
DJ_ADMIN_2FA = { "ISSUER_NAME": "Django Admin Example", }
| Setting | Default | Description |
|---|---|---|
REDIRECT_URL |
/admin/ |
URL to redirect to after successful verification |
LOGIN_URL |
/admin/ |
URL to Login Admin |
ISSUER_NAME |
Django Admin Example |
Name of the issuer |
TOTP_DIGITS |
6 |
Number of digits for the TOTP code |
TOTP_STEP |
30 |
Step size in seconds for TOTP code rotation |
TOTP_ALGORITHM |
'sha1' |
Algorithm used for TOTP ('sha1', 'sha256', 'sha512') |
BACKUP_CODES_COUNT |
10 |
Number of backup codes generated |
TRUSTED_DEVICE_DAYS |
30 |
Days to trust a device when user selects "Remember this device" |
VERIFICATION_TIMEOUT |
300 |
Default 5 minutes |
🧪 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-1.1.0.tar.gz.
File metadata
- Download URL: dj_admin_2fa-1.1.0.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f9d425a2d83b29fc4deb889a467ce698345e0677a7894522a5607b658527121
|
|
| MD5 |
ea005bf15210d1049786da31cad66cf2
|
|
| BLAKE2b-256 |
bb98b7932305715c6272dc71e86ea6a6917e25e2be19f8794ab82bb0987db92b
|