custom validation error in password_validators

57 views
Skip to first unread message

Mojtaba Akbari

unread,
Oct 24, 2022, 3:00:20 PM10/24/22
to Django developers (Contributions to Django itself)

i wanna have custom validation error in password_validators,
I can do this by rewriting the password validator classes and adding desired messages through options in the settings file and the password_validat section.

something like this :

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
        'OPTIONS': {
            'validation_error': 'My Custom Validation Error.',
        },
    },
    ...
]

and so on.

Apart from that I want to return custom validation error, for example in our company project we want to send our language based message without enabling t10n and l18n. Or ux writer wants to show the user the desired error according to business needs,
But it is not possible unless we directly override the password_validation classes and this is an extra and dirty work.

Is it worth the time? After spending some time, can I make a pull request?

Adam Johnson

unread,
Nov 2, 2022, 4:13:54 PM11/2/22
to django-d...@googlegroups.com
 But it is not possible unless we directly override the password_validation classes and this is an extra and dirty work.

I don't think this work is dirty!

We generally prefer to avoid extra settings (and sub-settings) where possible. The settings file should be clear, and not do what code can do. So, subclassing here would be the recommended approach, and it already works with released Django versions.

Moreover, NumericPasswordValidator is a pretty simple class. If you want a cuostmized version, you’re probably better off copy-pasting the implementation, and adjusting it as required.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/1038c5e4-1d86-4c50-90e2-2df7b8c9894dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages