From d3a918357cfa1289c8b1f6c27bb88b937d44d9e1 Mon Sep 17 00:00:00 2001 From: Nishant Gaglani Date: Wed, 24 Jul 2024 10:15:18 +0530 Subject: [PATCH] Closes #16964: Validate password when creating a new user or updating password for an existing user --- netbox/users/forms/model_forms.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/netbox/users/forms/model_forms.py b/netbox/users/forms/model_forms.py index 7a9f63ea7..c04b97b34 100644 --- a/netbox/users/forms/model_forms.py +++ b/netbox/users/forms/model_forms.py @@ -1,6 +1,6 @@ from django import forms from django.conf import settings -from django.contrib.auth import get_user_model +from django.contrib.auth import get_user_model, password_validation from django.contrib.postgres.forms import SimpleArrayField from django.core.exceptions import FieldError from django.utils.safestring import mark_safe @@ -226,6 +226,8 @@ class UserForm(forms.ModelForm): # 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.")) + if self.cleaned_data['password'] and self.cleaned_data['confirm_password']: + password_validation.validate_password(self.cleaned_data['confirm_password'], self.instance) class GroupForm(forms.ModelForm):