commit
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
|
||||
class LettersAndDigitsValidator:
|
||||
|
||||
def validate(self, password, user=None):
|
||||
vals = {
|
||||
'Password must contain an uppercase letter.': lambda s: any(x.isupper() for x in s),
|
||||
'Password must contain a lowercase letter.': lambda s: any(x.islower() for x in s),
|
||||
'Password must contain a digit.': lambda s: any(x.isdigit() for x in s),
|
||||
'Password cannot contain white spaces.': lambda s: not any(x.isspace() for x in s)
|
||||
'Password must contain an uppercase letter.': lambda s: any(x.isupper() for x in s),
|
||||
'Password must contain a lowercase letter.': lambda s: any(x.islower() for x in s),
|
||||
'Password must contain a digit.': lambda s: any(x.isdigit() for x in s),
|
||||
'Password cannot contain white spaces.': lambda s: not any(x.isspace() for x in s)
|
||||
}
|
||||
valid = None
|
||||
for n, val in vals.items():
|
||||
if not val(password):
|
||||
valid = False
|
||||
raise ValidationError(n)
|
||||
if not val(password):
|
||||
valid = False
|
||||
raise ValidationError(n)
|
||||
return valid
|
||||
|
||||
def get_help_text(self):
|
||||
|
||||
Reference in New Issue
Block a user