I think the best option is for you to write your own Validator and add it to your settings.py. Here in django doc you can see how to do, but it would be something like this draft I did below (I added only one example, missing implement all methods for validations):
from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _
class MyCustomValidator:
def __init__(self):
self.length = 10
self.max_upper_case = 2
self.max_lower_case = 2
self.max_int_case = 1
self.max_symbols_case = 2
def validate_length_password(self, password):
if len(self.password) < self.length:
return True
return False
def validate_upper_case(self, password):
pass
def validate_lower_case(self, password):
pass
def validate_int_case(self, password):
pass
def validate_max_symbols_case(self, password):
pass
def validate(self, password, user=None):
if self.validate_length_password(password):
raise ValidationError(
_("This password must contain at least "
"%(length)d characters."),
code='password_too_short',
params={'length': self.length},
)
def get_help_text(self):
return _(
"Your password must contain at least %(length)d characters."
% {'length': self.length}
)
From there on your settings.py in the AUTH_PASSWORD_VALIDATORS you add this class, like:
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'path.onde.ta.o.arquivo.do.seu.validator.finalizando.com.a.classe.MyCustomValidator',
},
]
What if the user puts accented letters in the password? The regular expression won’t pick them up.
– Woss
Thanks Ytalo, only the special characters did not work... but I understood the logic!
– Bianca C.