#31461: Make it easier to customize ValidationError messages in
contrib.auth.password_validation
-------------------------------------+-------------------------------------
Reporter: Joey van Breukelen | Owner: Joey van
Type: | Breukelen
Cleanup/optimization | Status: closed
Component: contrib.auth | Version: 3.0
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Joey van Breukelen):
Ok, makes sense to me.
Just want to note that MinimumLengthValidator (used in example) has a very
short validate method. UserAttributeSimilarityValidator for example, has a
more complicated one.
{{{
def validate(self, password, user=None):
if not user:
return
for attribute_name in self.user_attributes:
value = getattr(user, attribute_name, None)
if not value or not isinstance(value, str):
continue
value_parts = re.split(r'\W+', value) + [value]
for value_part in value_parts:
if SequenceMatcher(a=password.lower(),
b=value_part.lower()).quick_ratio() >= self.max_similarity:
try:
verbose_name =
str(user._meta.get_field(attribute_name).verbose_name)
except FieldDoesNotExist:
verbose_name = attribute_name
raise ValidationError(
_("The password is too similar to the
%(verbose_name)s."),
code='password_too_similar',
params={'verbose_name': verbose_name},
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31461#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/069.fcf5b8c95f02a757d4f6d2ba74b72828%40djangoproject.com.