I am trying to add custom password validators in Django but i can't figure out why it wouldn't import the module. Anyone has encountered this issue or can tell me why i have this error please ?
Here is the code in authentication/validators.py:
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext as _
class LowercaseValidator(object):
def validate(self, password, user=None):
if not re.findall('[a-z]', password):
raise ValidationError(
_("The password must contain at least 1 lowercase letter, a-z."),
code='password_no_lower',
)
def get_help_text(self):
return _(
"Your password must contain at least 1 lowercase letter, a-z."
)
Here is my updated settings.py
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'OPTIONS': {
'min_length': 12, }
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
{
'NAME': 'authentication.validators.LowercaseValidator',
},
]
And here is the error i have:
The module in NAME could not be imported: authentication.validators.LowercaseValidator. Check your AUTH_PASSWORD_VALIDATORS setting.
P.S: i did create an app called "authentication" and my validators.py is in the folder of the application.
Thank you in advance for your answers !