Opened 10 months ago
Closed 7 weeks ago
#35782 closed Cleanup/optimization (fixed)
Password validator custom error messages
Reported by: | bcail | Owned by: | bcail |
---|---|---|---|
Component: | contrib.auth | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Adam Zapletal | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
We would like to make it easier to customize the error messages raised by password validators.
Instead of having to override whole methods, could we put the error messages on the class as attributes, so we would only have to override that attribute for each class?
See the forum thread for discussion.
Note: ticket 34116 is a related ticket that was closed as wontfix, but it was asking for being able to pass the custom error messages through the settings, which is not what this ticket is suggesting.
Change History (15)
comment:1 by , 10 months ago
Cc: | added |
---|
comment:2 by , 10 months ago
Component: | Uncategorized → contrib.auth |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
Version: | 5.0 → dev |
comment:3 by , 10 months ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:4 by , 10 months ago
I reviewed the /pull request and confirmed that the change is working; do we need to update anything in the documentation based on the change?
comment:5 by , 10 months ago
Has patch: | set |
---|
comment:6 by , 9 months ago
The /pull request (including additions to documentation) look good to me, so I approved it.
comment:7 by , 9 months ago
Patch needs improvement: | set |
---|
comment:8 by , 9 months ago
Patch needs improvement: | unset |
---|
comment:9 by , 9 months ago
Patch needs improvement: | set |
---|
comment:10 by , 9 months ago
Patch needs improvement: | unset |
---|
comment:12 by , 9 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:14 by , 7 weeks ago
Resolution: | fixed |
---|---|
Status: | closed → new |
Hello,
In your recent change to django.contrib.auth.password_validation.MinimumLengthValidator.get_error_message, you removed the 'min_length' named placeholder from the translation string:
"This password is too short. It must contain at least %d characters."
It should be changed to:
"This password is too short. It must contain at least %(min_length)d characters."
As a result of this change, all languages except those listed below no longer work correctly. Additionally, the following translation files should be updated:
django/contrib/auth/locale/af/LC_MESSAGES/django.po
django/contrib/auth/locale/da/LC_MESSAGES/django.po
django/contrib/auth/locale/dsb/LC_MESSAGES/django.po
django/contrib/auth/locale/en/LC_MESSAGES/django.po
django/contrib/auth/locale/es_AR/LC_MESSAGES/django.po
django/contrib/auth/locale/et/LC_MESSAGES/django.po
django/contrib/auth/locale/fi/LC_MESSAGES/django.po
django/contrib/auth/locale/fr/LC_MESSAGES/django.po
django/contrib/auth/locale/he/LC_MESSAGES/django.po
django/contrib/auth/locale/hsb/LC_MESSAGES/django.po
django/contrib/auth/locale/hu/LC_MESSAGES/django.po
django/contrib/auth/locale/id/LC_MESSAGES/django.po
django/contrib/auth/locale/ko/LC_MESSAGES/django.po
django/contrib/auth/locale/lv/LC_MESSAGES/django.po
django/contrib/auth/locale/pl/LC_MESSAGES/django.po
django/contrib/auth/locale/pt/LC_MESSAGES/django.po
django/contrib/auth/locale/sq/LC_MESSAGES/django.po
django/contrib/auth/locale/sr/LC_MESSAGES/django.po
django/contrib/auth/locale/sr_Latn/LC_MESSAGES/django.po
django/contrib/auth/locale/tr/LC_MESSAGES/django.po
django/contrib/auth/locale/uk/LC_MESSAGES/django.po
django/contrib/auth/locale/zh_Hant/LC_MESSAGES/django.po
I believe the get_error_message function should be defined as follows:
def get_error_message(self): return ( 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, ) % {"min_length": self.min_length} )
If possible, I can make this change and update the corresponding test as well, as my first contribution :)
comment:15 by , 7 weeks ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This was discussed in #36378 and agreed that translations should be updated to the new string
Please do not reopen fixed tickets, instead raise a ticket if you can see this has not been discussed
Makes sense to me.