the following error occurs in my project:-
The module in NAME could not be imported: bookstore_app.validators.PasswordValidation. Check your AUTH_PASSWORD_VALIDATORS setting.
i created my own password validation and registered it on setting.py file like the following:-
setting.py
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'OPTIONS':{'min_length':6},
},
{
'NAME':'bookstore_app.validators.PasswordValidation'
},
]
validators.py file
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext as _
from .forms import registerForm
class PasswordValidation:
def __init__(self, min_length=1):
self.min_length = min_length
def validate(self, password, user=None):
special_characters = "[~\!@#\$%\^&\*\(\)_\+{}\":;'\[\]]"
if not any(char.isdigit() for char in password):
raise ValidationError(_('Password must contain at least %(min_length)d digit.') % {'min_length': self.min_length})
if not any(char.isalpha() for char in password):
raise ValidationError(_('Password must contain at least %(min_length)d letter.') % {'min_length': self.min_length})
if not any(char in special_characters for char in password):
raise ValidationError(_('Password must contain at least %(min_length)d special character.') % {'min_length': self.min_length})
def get_help_text(self):
return ""