Skip to main content

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:

  1. Insert django_static_jquery3, django_secure_password_input, django-simple-tags, captcha and django_admin_safe_login into INSTALLED_APPS.
  2. Application django_static_jquery3 provides static jquery.js.
  3. Application django_secure_password_input provides rsa encryption and decryption function for password field.
  4. Application django_admin_safe_login provides all functions about safe login.
  5. Application captcha provides image captcha functions.
  6. Application django-simple-tags provides custom template tags used in our admin/login.html.
  7. 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.
  8. Configurations about password RSA encryption, see details at https://pypi.org/project/django-secure-password-input/.
  9. Configurations about captcha, see detail at https://pypi.org/project/django-simple-captcha/.
  10. 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:

  1. Include captcha.urls is required so that the captcha image can be displayed.
  2. Reset Password Link only shows when you enabled admin_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.

  1. Our new admin/login.html extends from system's admin/login.html.
  2. We override the extrastyle block to add extra js and css.
  3. The function adding background image and changing login box position is implemented in our new extrastyle block.
  4. We override the whole content block.
  5. We copied the whole content block from django's default admin/login.html.
  6. 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

v0.1.0

  • First release.

v0.2.0

  • Add rsa encryption and decrption functions for password field.
  • Fix requirements.txt missing django-static-jquery3 problem.

v0.3.0

  • Add background image setting.
  • Add login box position setting.
  • Use admin/login.html override instead of creating a new template.
  • Fix document.
  • Fix translation.
  • Fix setup.py problem that include demo and example code in the final package.

v0.3.1

  • Rename zh_Hans to zh_hans.
  • Depends on django-static-jquery3>=5.0.0.

v0.3.2

  • Depends on django-secure-password-input>=0.1.1.

v0.3.3

  • Add django-app-requires support.
  • Add License file.

v0.3.4

  • Fix problems with django 3.2.
  • Auto get captcha refresh url.

v0.3.5

  • Fix ugettext problem for Django 4.2.

v0.3.6

  • Doc update.

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-safe-login-0.3.6.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

django_admin_safe_login-0.3.6-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file django-admin-safe-login-0.3.6.tar.gz.

File metadata

File hashes

Hashes for django-admin-safe-login-0.3.6.tar.gz
Algorithm Hash digest
SHA256 f7637902b3824dc709fa5d73d5c9c8341eb36ac4a7b9a97e44d9cc897e8098af
MD5 09a3cd95f4f9e8156f0282085a73e995
BLAKE2b-256 a1a8580a35c5bc398e5370589ded02e8be15cde752c412c1c5575128118d8ae9

See more details on using hashes here.

File details

Details for the file django_admin_safe_login-0.3.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_admin_safe_login-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c6dc689041d86f8fcdc8fe3d8ae6f438cfd29c66f6bc7cd16b99a4eedd727f0a
MD5 3463d0b8e1c459ed01de0ba4d61b48cc
BLAKE2b-256 0f676e960ce20caab7079c157867c2f1b5fbafd98ec0238bc3930b343c2ccb88

See more details on using hashes here.

Supported by

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