Skip to main content

Two-Factor Authentication for Django Admin with TOTP, backup codes, trusted devices, and more.

Project description

Django Admin 2FA Plus

PyPI version License: MIT Django Versions Build Status

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

  1. Log in to Django Admin.
  2. Go to /admin-2fa/setup/ to begin TOTP setup.
  3. Scan the QR code using your authenticator app.
  4. Enter the generated code to confirm.
  5. Save the backup codes displayed — each can be used once.
  6. 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:

  1. Fork the repository
  2. Create your feature branch: git checkout -b feature/my-feature
  3. Commit your changes: git commit -am 'Add new feature'
  4. Update code, if needed, as per pre-commit logs
  5. Push to the branch: git push origin feature/my-feature
  6. 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

django_admin_2fa_plus-0.1.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_admin_2fa_plus-0.1.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file django_admin_2fa_plus-0.1.0.tar.gz.

File metadata

  • Download URL: django_admin_2fa_plus-0.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.3

File hashes

Hashes for django_admin_2fa_plus-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8a437b7d87f27a15a51fa6b83aae035a533a61c41d5f28dec8579cf9fbc8e8c5
MD5 ebfd25a078f696a6fecb45f5445a6f93
BLAKE2b-256 2e671814060f413c464f8e38a951d1bc9f8f7630e01380cca2772d99d8abb634

See more details on using hashes here.

File details

Details for the file django_admin_2fa_plus-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_admin_2fa_plus-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 174c59c98833fe0f6fefe6320ad5428c897b4842928f4891d567f000d80e53c2
MD5 3ee2b768c13cff5a5729e4af4c5cd21d
BLAKE2b-256 67c859cc19af01732229bf1e2480a81efc4f87385f9e8464b847c8c34cf1b4ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page