Fakultas Ilmu Komputer UI

Commit ec71aef3 authored by Gregorius Aprisunnea's avatar Gregorius Aprisunnea
Browse files

implementing PasswordValidator and uncommenting other tests

parent 1e4a8b7d
This diff is collapsed.
import string
from django.core.exceptions import ValidationError
class PasswordPolicyValidator(object):
def validate(self, password, user=None):
if sum(c.isdigit() for c in password) < 1:
msg = 'Password must contain at least 1 number.'
raise ValidationError(msg)
if not any(c.isupper() for c in password):
msg = 'Password must contain at least 1 uppercase letter.'
raise ValidationError(msg)
if not any(c.islower() for c in password):
msg = 'Password must contain at least 1 lowercase letter.'
raise ValidationError(msg)
if not any(c for c in password if c in string.punctuation):
msg = 'Password must contain at least 1 special letter.'
raise ValidationError(msg)
if len(password) < 8 :
msg = 'Password must have at least 8 characters.'
raise ValidationError(msg)
def get_help_text(self):
return _(
"Your password is not complying to our password policy"
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment