mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-05 13:14:46 +02:00

Use Django's built-in password validators with reasonable settings, and add a basic complexity validator since there isn't one provided. Additionally, fix the registration form so that it shows the help text which includes a description of what the password requirements are. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
26 lines
867 B
Python
26 lines
867 B
Python
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"
|
|
)
|