Skip to main content

Django Middleware that requires a user to reset password

Project description

Resetty (Reset Password Middleware for Django). Banzai made.

This repo will add an automated functionallity into django apps to allow an automated password reset every 90 days (by default) for Staff and Superuser type users.

Install

From Pypi

pip install resetty

Setup

On your settings file:

Add the resetty app

INSTALLED_APPS += ['resetty']

Add the middleware

Add resetty's middleware after auth's AuthenticationMiddleware

'django.contrib.auth.middleware.AuthenticationMiddleware',
# Resetty must be placed after Session and Authentication Middleware
'resetty.middleware.ResetPasswordMiddleware', 

Add resetty's password validator

It's preferable if you add it at the top of your auth validators

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "resetty.auth_password_validators.DoNotReusePasswordValidator",
    },
    # ... other validators below
]

RESETTY OPTIONS

You can override resetty's default values in your settings file. The available options are:

RESETTY_USER_CATEGORIES_REQUIRING_RESET

  • Inspects your user's instance and determines if it needs to reset password based on the user flags
  • Type: list
  • Default value: ['is_staff']
  • Available values: ['is_staff'|'is_superuser'] that can be combined in the list.

RESETTY_RESET_PASSWORD_DELTA_DAYS

  • Delta time in days after last password update where we require a new one
  • Type: int
  • Default value: 90

RESETTY_RESET_PASSWORD_URL

  • URL where the user will reset her/his password.
  • Type: string
  • Default value: /admin/password_change/

RESETTY_REDIRECT_EXCLUDED_PATHS

  • URL paths which the middleware exempts from redirection. This is important to avoid request looping
  • Type: list
  • Default value: [ "/admin/login/", "/admin/logout/", "/admin/password_change/", "/admin/password_change/done/" ] and any route that matches the pattern r'\/?(.+)?\/reset\/?'

Last step

Set your local settings and build your container or pip install. Also, run your migrations.

Expected behavior after install

All views not included in RESETTY_REDIRECT_EXCLUDED_PATHS will require you to change your password if haven't. This behavior will be repeated everytime the passwrod expires (RESETTY_RESET_PASSWORD_DELTA_DAYS).

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

resetty-1.0.2.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

resetty-1.0.2-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file resetty-1.0.2.tar.gz.

File metadata

  • Download URL: resetty-1.0.2.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.0

File hashes

Hashes for resetty-1.0.2.tar.gz
Algorithm Hash digest
SHA256 8dcbe65dd2d2975ddeea337cb6f6542dbfb5f65e29f2dd8b5ceb3ba98d4817e2
MD5 d2fbb5c96cdddaf8d6e8664c62c48357
BLAKE2b-256 ff5fe38e93b6ea290a6da4fc660f310c725c3bb99e05a67ad67f589a300aa578

See more details on using hashes here.

File details

Details for the file resetty-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: resetty-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.0

File hashes

Hashes for resetty-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 127648b8586c998e1c88a4f5eb20835abb50dca8ee9f9768c224f08df1d89787
MD5 08f58d5b5b72f2b6299b096ab1666b5c
BLAKE2b-256 bddddc6e09381c64cffe4150f7f8941c93e73fca3695ffa5ef3b5aed0374f48f

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