code: def clean_new_password2(self):
          
          password1 = self.cleaned_data.get('new_password1')
          password2 = self.cleaned_data.get('new_password2')
          if password1 or password2:
              if password1 != password2:
                  raise forms.ValidationError(
                      self.error_messages['password_mismatch'],
                      code='password_mismatch',
                  )
              password_validation.validate_password(password2, self.instance)
          return password2
docs: Validate password when set