Package: django-password-policies-validator
django-password-policies-validator is a Django app to validate password complexity and prevent users from reusing previous passwords.Quick startAdd “password_policies” to your INSTALLED_APPS setting like this:INSTALLED_APPS = [
    ...
    'password_policies',
]Add validators to AUTH_PASSWORD_VALIDATORS setting:AUTH_PASSWORD_VALIDATORS = [
    ...
    {
        'NAME': 'password_policies.password_validation.ComplexityValidator',
    },
    {
        'NAME': 'password_policies.password_validation.ReusedPasswordValidator',
    },
    {
        'NAME': 'password_policies.password_validation.MinimumChangeIntervalValidator',
    },
]AppendPasswordExpirationMiddlewareto MIDDLEWARE setting, note that this must be listedafterthe'django.contrib.auth.middleware.AuthenticationMiddleware'MIDDLEWARE = [
    ...
    'password_policies.middleware.PasswordExpirationMiddleware',
]Runpython manage.py migrateto create thePasswordRecordmodels.Start the development server and go to the “Change password” page to check how the new password policies applied.TheValidatorclassesCustom options can be passed into validators by the following syntaxAUTH_PASSWORD_VALIDATORS = [
    ...
    {
        'NAME': 'password_policies.password_validation.ComplexityValidator',
        'OPTIONS': {
            'min_char_categories': 3,
            'min_numeric_chars': 2,
        }
    },
]Available options of each validator and their default values are listed below.ComplexityValidator(min_char_categories=4, min_numeric_chars=1, min_uppercase_chars=1, min_lowercase_chars=1, min_special_chars=1)Validates that the password is complex enough by checking how many categories of characters it contains, or the count of certain category of characters. Characters are devided into four categories:Uppercase alphabet characters A-ZLowercase alphabet characters a-zNumeric characters 0-9Non-alphanumeric (special) charactersmin_char_categoriesThe minimum categories of characters that the password should contain out of the four categories above. Value should be between 1 and 4.min_numeric_charsThe minimum count of numeric characters that the password should contain. Value should be 0 or any positive integer.min_uppercase_charsThe minimum count of uppercase characters that the password should contain. Value should be 0 or any positive integer.min_lowercase_charsThe minimum count of lowercase characters that the password should contain. Value should be 0 or any positive integer.min_special_charsThe minimum count of special characters that the password should contain. Value should be 0 or any positive integer.ReusedPasswordValidator(record_length=3)Remembers the user’s previousnpasswords and validate the new password doed not repeat any of them.record_lengthThe number of previous password records that the validator should compare against. Value should be any positive integer.MinimumChangeIntervalValidator(min_interval=1)Prevent the user from changing the password again within certain period of time. This is to avoid the user to bypassReusedPasswordValidatorand reuse the old password by changing passwords repeatedly in a short period of time.min_intervalThe minimum time interval (in days) of two consecutive password change attempts. Value should be any positive interger or float.ThePasswordExpirationMiddlewareclassPasswordExpirationMiddlewareChecks the user’s password-changing records, if the user’s password is expired, redirect the user to the password-changing form and shows a warning message.This middleware works for any urls under theadminapplication namespace and redirects to thepassword_changeurl under the same namespace of the page which the user is redirected from. Urls not under theadminapplication namespace are not redirected.The password expires in 90 days by default, and the number can be set by providing settingPASSWORD_EXPIRATION_DAYSto an integer or float value insettings.py.