Django Password Validators
raw JSON → 1.7.3 verified Fri May 01 auth: no python
A collection of additional password validators for Django, including checks for length, complexity, common passwords, and more. Current version: 1.7.3. Release cadence is irregular; last update 2022.
pip install django-password-validators Common errors
error ModuleNotFoundError: No module named 'password_validators.validators' ↓
cause Importing from the wrong submodule; validators are directly in the package.
fix
Change import to 'from password_validators import PasswordValidator'
error ImproperlyConfigured: The password validators setting must be a list or tuple. ↓
cause AUTH_PASSWORD_VALIDATORS is not formatted correctly in settings.py.
fix
Ensure it is a list of dictionaries with 'NAME' and optional 'OPTIONS'.
error KeyError: 'min_length' (or similar) when using validator. ↓
cause Missing or misspelled option key in the validator's OPTIONS.
fix
Check the validator's documentation for required option names.
Warnings
deprecated The 'UniqueValidator' and 'RepetitionValidator' were removed in version 1.1.0. ↓
fix Use 'ComplexityValidator' with appropriate options or custom validators.
breaking Django < 1.11 is not supported. ↓
fix Upgrade Django or use older version of the package.
gotcha The import path changed in version 1.0.0 from 'password_validators' to 'password_validators' (package name). Some tutorials show old import. ↓
fix Use 'from password_validators import ...' not 'from password_validators.validators import ...'.
Imports
- PasswordValidator wrong
from password_validators.validators import PasswordValidatorcorrectfrom password_validators import PasswordValidator
Quickstart
# settings.py
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'password_validators.LengthValidator',
'OPTIONS': {
'min_length': 12,
'max_length': 128,
}
},
{
'NAME': 'password_validators.ComplexityValidator',
'OPTIONS': {
'length': 8,
'upper': 1,
'lower': 1,
'digit': 1,
'special': 1,
}
},
{
'NAME': 'password_validators.CommonPasswordValidator',
'OPTIONS': {}
},
]