[Django] #35782: Password validator custom error messages

20 views
Skip to first unread message

Django

unread,
Sep 23, 2024, 9:54:24 AM9/23/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
-----------------------+-----------------------------------------
Reporter: bcail | Type: Uncategorized
Status: new | Component: Uncategorized
Version: 5.0 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------+-----------------------------------------
We would like to make it easier to customize the error messages raised by
[https://github.com/django/django/blob/main/django/contrib/auth/password_validation.py
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 [https://forum.djangoproject.com/t/password-validator-custom-error-
messages/34951 the forum thread] for discussion.

Note: [https://code.djangoproject.com/ticket/34116 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/35782>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 23, 2024, 10:02:58 AM9/23/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
-------------------------------+--------------------------------------
Reporter: bcail | Owner: (none)
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 5.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Adam Zapletal):

* cc: Adam Zapletal (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:1>

Django

unread,
Sep 24, 2024, 2:11:54 PM9/24/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
--------------------------------------+------------------------------------
Reporter: bcail | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: contrib.auth | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Claude Paroz):

* component: Uncategorized => contrib.auth
* stage: Unreviewed => Accepted
* type: Uncategorized => Cleanup/optimization
* version: 5.0 => dev

Comment:

Makes sense to me.
--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:2>

Django

unread,
Sep 24, 2024, 2:53:24 PM9/24/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
--------------------------------------+------------------------------------
Reporter: bcail | Owner: bcail
Type: Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by bcail):

* owner: (none) => bcail
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:3>

Django

unread,
Sep 27, 2024, 12:21:20 PM9/27/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
--------------------------------------+------------------------------------
Reporter: bcail | Owner: bcail
Type: Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Dmitriy Chukhin):

I reviewed the [https://github.com/django/django/pull/18620 /pull request]
and confirmed that the change is working; do we need to update anything in
the documentation based on the change?
--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:4>

Django

unread,
Sep 27, 2024, 1:55:03 PM9/27/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
--------------------------------------+------------------------------------
Reporter: bcail | Owner: bcail
Type: Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by bcail):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:5>

Django

unread,
Oct 8, 2024, 9:26:28 AM10/8/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
--------------------------------------+------------------------------------
Reporter: bcail | Owner: bcail
Type: Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Dmitriy Chukhin):

The [https://github.com/django/django/pull/18620 /pull request] (including
additions to documentation) look good to me, so I approved it.
--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:6>

Django

unread,
Oct 9, 2024, 11:48:50 AM10/9/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
--------------------------------------+------------------------------------
Reporter: bcail | Owner: bcail
Type: Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:7>

Django

unread,
Oct 9, 2024, 2:53:23 PM10/9/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
--------------------------------------+------------------------------------
Reporter: bcail | Owner: bcail
Type: Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by bcail):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:8>

Django

unread,
Oct 14, 2024, 5:46:01 AM10/14/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
--------------------------------------+------------------------------------
Reporter: bcail | Owner: bcail
Type: Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:9>

Django

unread,
Oct 14, 2024, 9:34:36 AM10/14/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
--------------------------------------+------------------------------------
Reporter: bcail | Owner: bcail
Type: Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by bcail):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:10>

Django

unread,
Oct 15, 2024, 6:48:55 AM10/15/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
--------------------------------------+------------------------------------
Reporter: bcail | Owner: bcail
Type: Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"80c3697e96f5a0cbeac043dd5a67f26c076a4279" 80c3697]:
{{{#!CommitTicketReference repository=""
revision="80c3697e96f5a0cbeac043dd5a67f26c076a4279"
Refs #35782 -- Documented the get_help_text methods in password
validators.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:11>

Django

unread,
Oct 15, 2024, 7:04:35 AM10/15/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
-------------------------------------+-------------------------------------
Reporter: bcail | Owner: bcail
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.auth | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:12>

Django

unread,
Oct 15, 2024, 11:23:48 AM10/15/24
to django-...@googlegroups.com
#35782: Password validator custom error messages
-------------------------------------+-------------------------------------
Reporter: bcail | Owner: bcail
Type: | Status: closed
Cleanup/optimization |
Component: contrib.auth | Version: dev
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"ec7d69035a408b357f1803ca05a7c991cc358cfa" ec7d6903]:
{{{#!CommitTicketReference repository=""
revision="ec7d69035a408b357f1803ca05a7c991cc358cfa"
Fixed #35782 -- Allowed overriding password validation error messages.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:13>

Django

unread,
May 21, 2025, 9:58:16 AMMay 21
to django-...@googlegroups.com
#35782: Password validator custom error messages
-------------------------------------+-------------------------------------
Reporter: bcail | Owner: bcail
Type: | Status: new
Cleanup/optimization |
Component: contrib.auth | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hamidreza Samsami):

* resolution: fixed =>
* status: closed => new

Comment:

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.
--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:14>

Django

unread,
May 21, 2025, 10:17:13 AMMay 21
to django-...@googlegroups.com
#35782: Password validator custom error messages
-------------------------------------+-------------------------------------
Reporter: bcail | Owner: bcail
Type: | Status: closed
Cleanup/optimization |
Component: contrib.auth | Version: dev
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => fixed
* status: new => closed

Comment:

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
--
Ticket URL: <https://code.djangoproject.com/ticket/35782#comment:15>
Reply all
Reply to author
Forward
0 new messages