This app provides configurable rotation of passwords.
- Configurable password duration and warning duration
- Visual warning to user using Django messages
- Prevents user from accessing any page in after expiration unless the password is changed
- Forces the new password to be different from previously used passwords
- Prevents similar passwords (ex: "password1", "password2", ...)
This Django app requires Python >= 3.6 and has been tested with Django 4.2.
pip install django-password-rotate
.- Add
password_rotate
toINSTALLED_APPS
. - Add
'password_rotate.middleware.PasswordRotateMiddleware'
toMIDDLEWARE
. It should be listed after authentication and session middlewares. - Add
password_rotate.validators.NotPreviousPasswordValidator
toAUTH_PASSWORD_VALIDATORS
:
AUTH_PASSWORD_VALIDATORS = [
...
{
"NAME": "password_rotate.validators.NotPreviousPasswordValidator",
},
]
- Add the pattern in the urls of your project:
urlpatterns = [
...
path("password_rotate/", include("password_rotate.urls")),
]
- Configure the app in your settings:
# rotate passwords after 90 days PASSWORD_ROTATE_SECONDS = 90 * 24 * 60 * 60 # start warning 10 days before expiration PASSWORD_ROTATE_WARN_SECONDS = 10 * 24 * 60 * 60 # keep at most the 3 previous (encrypted) passwords PASSWORD_ROTATE_HISTORY_COUNT = 3 # when changing the password, allow only a new password with similarity ratio greater than 50 PASSWORD_ROTATE_MAX_SIMILARITY_RATIO = 50
- Run
python manage.py migrate
to create the required database tables.
If you want to exclude superusers from the password expiration, set this flag:
PASSWORD_ROTATE_EXCLUDE_SUPERUSERS = True
This app is a direct modification of: