mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-04 20:54:47 +02:00

Use django.utils.translation.gettext instead Signed-off-by: Tim Orling <tim.orling@konsulko.com>
28 lines
898 B
Python
28 lines
898 B
Python
# SPDX-License-Identifier: MIT
|
|
|
|
from django.core.exceptions import ValidationError
|
|
from django.utils.translation import gettext 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"
|
|
)
|