blob: 866925057ad6889efe1d4850e7ccc0bfe955a2f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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"
)
|