Uninett / nav

Network Administration Visualized
GNU General Public License v3.0
180 stars 37 forks source link

Allow pluggable password-policies #2808

Open hmpf opened 6 months ago

hmpf commented 6 months ago

Different organizations have different policies for password quality. The current policy for local users is hardcoded.

hmpf commented 6 months ago

Django already supports this, it is only a matter of using the existing functionality and wrapping it in our own config-system. https://docs.djangoproject.com/en/3.2/topics/auth/passwords/#module-django.contrib.auth.password_validation

hmpf commented 6 months ago

Example policy we need to easily support:

A, B, C, D configurable but defaults to 1.

The only relevant validator that comes with Django is django.contrib.auth.password_validation.MinimumLengthValidator.

We need to write our own validator for the four M character validators. I assume that it must be possible to further specify which "special" characters are valid, but we do need a default.

Maybe have an "OR"-validator that takes lists of validators as an option? Should we have one validator per specification, or a single one covering uppercase, lowercase, numbers and specials?

hmpf commented 6 months ago

The Django app django-password-validators supports sub-rules i-iv with a single validator: django_password_validators.password_character_requirements.password_validation.PasswordCharacterValidator

On second look, it drags in a lot of things we don't need like forms and views and a password history watcher.

hmpf commented 6 months ago

Here's another: https://github.com/i3thuan5/django-password-policies-validator