diff options
Diffstat (limited to 'django/contrib/auth/password_validation.py')
| -rw-r--r-- | django/contrib/auth/password_validation.py | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/django/contrib/auth/password_validation.py b/django/contrib/auth/password_validation.py index 06f8fcc4e8..d24e69e0ce 100644 --- a/django/contrib/auth/password_validation.py +++ b/django/contrib/auth/password_validation.py @@ -106,17 +106,16 @@ class MinimumLengthValidator: def validate(self, password, user=None): if len(password) < self.min_length: - raise ValidationError( - ngettext( - "This password is too short. It must contain at least " - "%(min_length)d character.", - "This password is too short. It must contain at least " - "%(min_length)d characters.", - self.min_length, - ), - code="password_too_short", - params={"min_length": self.min_length}, - ) + raise ValidationError(self.get_error_message(), code="password_too_short") + + def get_error_message(self): + return ngettext( + "This password is too short. It must contain at least %d character." + % self.min_length, + "This password is too short. It must contain at least %d characters." + % self.min_length, + self.min_length, + ) def get_help_text(self): return ngettext( @@ -203,11 +202,14 @@ class UserAttributeSimilarityValidator: except FieldDoesNotExist: verbose_name = attribute_name raise ValidationError( - _("The password is too similar to the %(verbose_name)s."), + self.get_error_message(), code="password_too_similar", params={"verbose_name": verbose_name}, ) + def get_error_message(self): + return _("The password is too similar to the %(verbose_name)s.") + def get_help_text(self): return _( "Your password can’t be too similar to your other personal information." @@ -242,10 +244,13 @@ class CommonPasswordValidator: def validate(self, password, user=None): if password.lower().strip() in self.passwords: raise ValidationError( - _("This password is too common."), + self.get_error_message(), code="password_too_common", ) + def get_error_message(self): + return _("This password is too common.") + def get_help_text(self): return _("Your password can’t be a commonly used password.") @@ -258,9 +263,12 @@ class NumericPasswordValidator: def validate(self, password, user=None): if password.isdigit(): raise ValidationError( - _("This password is entirely numeric."), + self.get_error_message(), code="password_entirely_numeric", ) + def get_error_message(self): + return _("This password is entirely numeric.") + def get_help_text(self): return _("Your password can’t be entirely numeric.") |
