Add captcha field for django admin's login page.
Project description
django-admin-safe-login
Add captcha field and rsa encryption password field for django admin's login page.
Install
pip install django-admin-safe-login
Usage
pro/settings.py
INSTALLED_APPS = [
...
'django_static_jquery3',
'django_secure_password_input',
'django_simple_tags',
'captcha',
'django_admin_safe_login',
...
]
CAPTCHA_IMAGE_SIZE = (100, 30) # required
DJANGO_ADMIN_SAFE_LOGIN_ENABLE_CAPTCHA = True # optional, default to True
DJANGO_ADMIN_SAFE_LOGIN_BACKGROUND_IMAGE = "django-admin-safe-login/img/example-background.jpg" # optional, default to no-image.
DJANGO_ADMIN_SAFE_LOGIN_BOX_MARGIN_RIGHT = "200px" # optional, default to auto
DJANGO_ADMIN_SAFE_LOGIN_BOX_MARGIN_LEFT = "auto" # optional, default to auto
DJANGO_ADMIN_SAFE_LOGIN_BOX_MARGIN_TOP = "100px" # optional, default to auto
DJANGO_ADMIN_SAFE_LOGIN_BOX_MARGIN_BOTTOM = "100px" # optional, default to auto
DJANGO_ADMIN_SAFE_LOGIN_TEMPLATE = "" # optional, default to "admin/login.html".
Note:
- Insert django_static_jquery3, django_secure_password_input, django-simple-tags, captcha and django_admin_safe_login into INSTALLED_APPS.
- Application django_static_jquery3 provides static jquery.js.
- Application django_secure_password_input provides rsa encryption and decryption function for password field.
- Application django_admin_safe_login provides all functions about safe login.
- Application captcha provides image captcha functions.
- Application django-simple-tags provides custom template tags used in our admin/login.html.
- Configuration item CAPTCHA_IMAGE_SIZE is required, and must set to (100, 30) so that it will not break the display style. If you want other size image, you have to rewrite some css code.
- Configurations about password RSA encryption, see details at https://pypi.org/project/django-secure-password-input/.
- Configurations about captcha, see detail at https://pypi.org/project/django-simple-captcha/.
- Configurations about password reset, see detail at https://docs.djangoproject.com/en/3.0/ref/contrib/admin/ (search: Adding a password reset feature).
pro/urls.py
from django.urls import path
from django.urls import include
from django.contrib.auth import views as auth_views
urlpatterns = [
...
path(
'admin/password_reset/',
auth_views.PasswordResetView.as_view(),
name='admin_password_reset',
),
path(
'admin/password_reset/done/',
auth_views.PasswordResetDoneView.as_view(),
name='password_reset_done',
),
path(
'reset/<uidb64>/<token>/',
auth_views.PasswordResetConfirmView.as_view(),
name='password_reset_confirm',
),
path(
'reset/done/',
auth_views.PasswordResetCompleteView.as_view(),
name='password_reset_complete',
),
path('captcha/', include("captcha.urls")),
...
]
Note:
- Include captcha.urls is required so that the captcha image can be displayed.
Reset Password Link
only shows when you enabledadmin_password_reset
views in your urls.
Changes about admin/login.html
We have override some part of admin/login.html. But the admin/login.html content may change in future releases. So you should known what part is overrided.
- Our new admin/login.html extends from system's admin/login.html.
- We override the extrastyle block to add extra js and css.
- The function adding background image and changing login box position is implemented in our new extrastyle block.
- We override the whole content block.
- We copied the whole content block from django's default admin/login.html.
- We added blocks inside content block: form, form-row-username, from-row-password, form-row-extra, form-row-captcha, password-reset-url, before-submit-row, submit-row, after-submit-row.
Releases
Release | Time | Changes |
---|---|---|
v0.1.0 | 2020/03/06 | 1. First release. |
v0.2.0 | 2020/03/07 | 2. Add rsa encryption and decrption functions for password field. 3. Fix requirements.txt missing django-static-jquery3 problem. |
v0.3.0 | 2020/05/20 | 4. Add background image setting. 5. Add login box position setting. 6. Use admin/login.html override instead of creating a new template. 7. Fix document. 8. Fix translation. 9. Fix setup.py problem that include demo and example code in the final package. |
v0.3.1 | 2020/09/01 | 10. Rename zh_Hans to zh_hans. 11. Depends on django-static-jquery3>=5.0.0. |
v0.3.2 | 2020/09/01 | 12. Depends on django-secure-password-input>=0.1.1. |
v0.3.3 | 2020/09/24 | 13. Add app_requires. 14. Add License file. |
v0.3.4 | 2021/04/12 | 15. Test with django 3.2. 16. Auto get captcha refresh url. |
v0.3.5 | 2023/04/11 | 17. Fix ugettext problem for Django 4.2. |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-admin-safe-login-0.3.5.tar.gz
.
File metadata
- Download URL: django-admin-safe-login-0.3.5.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d98e8e739295a1c59f06e05740389f5db6d3c8eae2efeba183acbe4dacd2882 |
|
MD5 | 1476d31d882b08703580349b555436bf |
|
BLAKE2b-256 | ef24a0833f081244a384ea75a96592039d8da34cb39f74821933d28d2c7e25a3 |
File details
Details for the file django_admin_safe_login-0.3.5-py3-none-any.whl
.
File metadata
- Download URL: django_admin_safe_login-0.3.5-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42ed220f21df7bbe77fdec99bbdba6b18b492d94b5ac9052af9a0a1d46d9505f |
|
MD5 | 8857d76abbee6ebb3aac9374a1e8ac3e |
|
BLAKE2b-256 | 2ee468dc2cc0b3b0e9d28d912efbcaf5476865ee0d4c5d22443e60b309d3a716 |