mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-07 16:18:16 -06:00
17289 add password validation
This commit is contained in:
parent
30822ee7d1
commit
85229faad0
27
netbox/utilities/password_validation.py
Normal file
27
netbox/utilities/password_validation.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
|
||||||
|
class NumericAlphaPasswordValidator:
|
||||||
|
"""
|
||||||
|
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 should have at least one numeral"),
|
||||||
|
)
|
||||||
|
|
||||||
|
if not any(char.isupper() for char in password):
|
||||||
|
raise ValidationError(
|
||||||
|
_("Password should have at least one uppercase letter"),
|
||||||
|
)
|
||||||
|
|
||||||
|
if not any(char.islower() for char in password):
|
||||||
|
raise ValidationError(
|
||||||
|
_("Password should 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.")
|
Loading…
Reference in New Issue
Block a user