diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index a759dcfd3..2c0130275 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -63,9 +63,6 @@ ADMINS = getattr(configuration, 'ADMINS', []) ALLOW_TOKEN_RETRIEVAL = getattr(configuration, 'ALLOW_TOKEN_RETRIEVAL', True) ALLOWED_HOSTS = getattr(configuration, 'ALLOWED_HOSTS') # Required AUTH_PASSWORD_VALIDATORS = getattr(configuration, 'AUTH_PASSWORD_VALIDATORS', [ - { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", - }, { "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", "OPTIONS": { diff --git a/netbox/users/forms/model_forms.py b/netbox/users/forms/model_forms.py index ad3f50d2c..639b9f726 100644 --- a/netbox/users/forms/model_forms.py +++ b/netbox/users/forms/model_forms.py @@ -2,7 +2,7 @@ from django import forms from django.conf import settings from django.contrib.auth import password_validation from django.contrib.postgres.forms import SimpleArrayField -from django.core.exceptions import FieldError, ValidationError +from django.core.exceptions import FieldError from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ @@ -221,21 +221,16 @@ class UserForm(forms.ModelForm): return instance - def _post_clean(self): - super()._post_clean() - # Validate the password after self.instance is updated with form data - if self.cleaned_data['password']: - try: - password_validation.validate_password(self.cleaned_data['password'], self.instance) - except ValidationError as error: - self.add_error('password', error) - def clean(self): # Check that password confirmation matches if password is set if self.cleaned_data['password'] and self.cleaned_data['password'] != self.cleaned_data['confirm_password']: raise forms.ValidationError(_("Passwords do not match! Please check your input and try again.")) + # Enforce password validation rules (if configured) + if self.cleaned_data['password']: + password_validation.validate_password(self.cleaned_data['password'], self.instance) + class GroupForm(forms.ModelForm): users = DynamicModelMultipleChoiceField(