diff options
Diffstat (limited to 'password_validation.py')
-rw-r--r-- | password_validation.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/password_validation.py b/password_validation.py new file mode 100644 index 0000000..8669250 --- /dev/null +++ b/password_validation.py @@ -0,0 +1,25 @@ +from django.core.exceptions import ValidationError +from django.utils.translation import ugettext as _ + +import re + +class ComplexityValidator(object): + def validate(self, password, user=None): + score = 0 + if re.search('[0-9]', password): + score += 1 + if password.lower() != password: + score += 1 + if re.search('[^a-zA-Z0-9]', password): + score += 1 + + if score < 2: + raise ValidationError( + _("This password does not contain at least two of: upper/lowercase characters; a number; a special (non-alphanumeric) character."), + code='password_too_simple' + ) + + def get_help_text(self): + return _( + "Your password must contain at least two of: upper/lowercase characters; a number; a special (non-alphanumeric) character" + ) |