mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 04:02:52 -06:00

* 17289 add password validation * 17289 add password validation * 17289 fix tests * 17289 fix tests * Update netbox/utilities/password_validation.py Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com> * Update netbox/utilities/password_validation.py Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com> * Update netbox/utilities/password_validation.py Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com> * 17289 update tests * 17289 remove common password check * 17289 fix user create * 17289 revert _post_clean --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
28 lines
979 B
Python
28 lines
979 B
Python
from django.core.exceptions import ValidationError
|
|
from django.utils.translation import gettext as _
|
|
|
|
|
|
class AlphanumericPasswordValidator:
|
|
"""
|
|
Validate that the password has at least one numeral, one uppercase letter and one lowercase letter.
|
|
"""
|
|
|
|
def validate(self, password, user=None):
|
|
if not any(char.isdigit() for char in password):
|
|
raise ValidationError(
|
|
_("Password must have at least one numeral."),
|
|
)
|
|
|
|
if not any(char.isupper() for char in password):
|
|
raise ValidationError(
|
|
_("Password must have at least one uppercase letter."),
|
|
)
|
|
|
|
if not any(char.islower() for char in password):
|
|
raise ValidationError(
|
|
_("Password must have at least one lowercase letter."),
|
|
)
|
|
|
|
def get_help_text(self):
|
|
return _("Your password must contain at least one numeral, one uppercase letter and one lowercase letter.")
|