django-zxcvbn-password-validator

raw JSON →
1.6.0 verified Fri May 01 auth: no python

A Django password validator that integrates zxcvbn-python to enforce password strength checks with translatable feedback. Current version 1.6.0, supports Python >=3.6 and Django 2.2+. Maintained on GitHub by pych卉.

pip install django-zxcvbn-password-validator
error ModuleNotFoundError: No module named 'django_zxcvbn_password_validator'
cause Library not installed or wrong import path.
fix
Run: pip install django-zxcvbn-password-validator. Then import using: from django_zxcvbn_password_validator import ZXCVBNValidator
error KeyError: 'NAME'
cause Incorrect validator configuration syntax in settings.
fix
Use the correct dictionary format: {'NAME': 'django_zxcvbn_password_validator.ZXCVBNValidator', 'OPTIONS': {...}}
error AttributeError: 'Settings' object has no attribute 'AUTH_PASSWORD_VALIDATORS'
cause Django version older than 1.9 or missing password validation support.
fix
Upgrade Django to at least 1.9 or define AUTH_PASSWORD_VALIDATORS in settings.
gotcha The library is not compatible with Django >=3.2 if you rely on the old password validators format? Actually it works with Django 2.2+ but check your Django version for generic validators support.
fix Use the validator class path as 'django_zxcvbn_password_validator.ZXCVBNValidator'.
deprecated Defining validators via list of strings is deprecated in Django 4.x; use the new tuple format or classes. This library works with the string path format in current versions.
fix If using Django 4.x, consider switching to the class-based definition: ZXCVBNValidator(min_score=3, user_attributes=(...))
gotcha The 'user_attributes' option uses Django's User model fields by default; if you have custom user model, provide the actual field names; missing attributes can cause AttributeError.
fix Ensure custom user model has the fields listed, or omit user_attributes entirely.

Add the validator to AUTH_PASSWORD_VALIDATORS in Django settings.

# settings.py
AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django_zxcvbn_password_validator.ZXCVBNValidator',
        'OPTIONS': {
            'min_score': 3,
            'user_attributes': ('username', 'email', 'first_name', 'last_name')
        }
    }
]