diff --git a/accountsplus/validators.py b/accountsplus/validators.py index 51b5898..2632e64 100644 --- a/accountsplus/validators.py +++ b/accountsplus/validators.py @@ -14,3 +14,16 @@ def validate(self, password, user=None): def get_help_text(self): return _('Password should contain uppercase, lowercase, numeric values and at least ' 'one of the following $@#!%*?&') + + +class CustomPasswordValidator(object): + + def validate(self, password, user=None): + regex = '(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[A-Za-z\d$@#!%*\?&`+-_^/]' + if not re.match(regex, password): + raise ValidationError(_('Password should contain uppercase, lowercase, numeric values and at least ' + 'one of the following $@#!%*?&'), code='password_is_weak') + + def get_help_text(self): + return _('Password should contain uppercase, lowercase, numeric values and at least ' + 'one of the following $@#!%*?&')