diff options
| author | Ben Cail <bcail@crossway.org> | 2024-09-26 10:11:41 -0400 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-10-15 17:23:39 +0200 |
| commit | ec7d69035a408b357f1803ca05a7c991cc358cfa (patch) | |
| tree | 63b1146a137bcaf35901c39854ad8cd0af142760 /docs | |
| parent | 06bf06a911695c5c84f746742f764c040e237ece (diff) | |
Fixed #35782 -- Allowed overriding password validation error messages.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/releases/5.2.txt | 4 | ||||
| -rw-r--r-- | docs/topics/auth/passwords.txt | 39 |
2 files changed, 39 insertions, 4 deletions
diff --git a/docs/releases/5.2.txt b/docs/releases/5.2.txt index 78c96688cf..806abfa26d 100644 --- a/docs/releases/5.2.txt +++ b/docs/releases/5.2.txt @@ -82,6 +82,10 @@ Minor features improves performance. See :ref:`adding an async interface <writing-authentication-backends-async-interface>` for more details. +* The :ref:`password validator classes <included-password-validators>` + now have a new method ``get_error_message()``, which can be overridden in + subclasses to customize the error messages. + :mod:`django.contrib.contenttypes` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/topics/auth/passwords.txt b/docs/topics/auth/passwords.txt index e8a662e239..8efd2bdebf 100644 --- a/docs/topics/auth/passwords.txt +++ b/docs/topics/auth/passwords.txt @@ -590,6 +590,8 @@ has no settings. The help texts and any errors from password validators are always returned in the order they are listed in :setting:`AUTH_PASSWORD_VALIDATORS`. +.. _included-password-validators: + Included validators ------------------- @@ -600,10 +602,18 @@ Django includes four validators: Validates that the password is of a minimum length. The minimum length can be customized with the ``min_length`` parameter. + .. method:: get_error_message() + + .. versionadded:: 5.2 + + A hook for customizing the ``ValidationError`` error message. Defaults + to ``"This password is too short. It must contain at least <min_length> + characters."``. + .. method:: get_help_text() A hook for customizing the validator's help text. Defaults to ``"Your - password must contain at least <min_length> characters."`` + password must contain at least <min_length> characters."``. .. class:: UserAttributeSimilarityValidator(user_attributes=DEFAULT_USER_ATTRIBUTES, max_similarity=0.7) @@ -622,10 +632,17 @@ Django includes four validators: ``user_attributes``, whereas a value of 1.0 rejects only passwords that are identical to an attribute's value. + .. method:: get_error_message() + + .. versionadded:: 5.2 + + A hook for customizing the ``ValidationError`` error message. Defaults + to ``"The password is too similar to the <user_attribute>."``. + .. method:: get_help_text() A hook for customizing the validator's help text. Defaults to ``"Your - password can’t be too similar to your other personal information."`` + password can’t be too similar to your other personal information."``. .. class:: CommonPasswordValidator(password_list_path=DEFAULT_PASSWORD_LIST_PATH) @@ -638,19 +655,33 @@ Django includes four validators: common passwords. This file should contain one lowercase password per line and may be plain text or gzipped. + .. method:: get_error_message() + + .. versionadded:: 5.2 + + A hook for customizing the ``ValidationError`` error message. Defaults + to ``"This password is too common."``. + .. method:: get_help_text() A hook for customizing the validator's help text. Defaults to ``"Your - password can’t be a commonly used password."`` + password can’t be a commonly used password."``. .. class:: NumericPasswordValidator() Validate that the password is not entirely numeric. + .. method:: get_error_message() + + .. versionadded:: 5.2 + + A hook for customizing the ``ValidationError`` error message. Defaults + to ``"This password is entirely numeric."``. + .. method:: get_help_text() A hook for customizing the validator's help text. Defaults to ``"Your - password can’t be entirely numeric."`` + password can’t be entirely numeric."``. Integrating validation ---------------------- |
