Skip to content

Commit

Permalink
validate that password matches the rules
Browse files Browse the repository at this point in the history
  • Loading branch information
matmair committed Jun 16, 2022
1 parent 3d20f7c commit b9c9f5b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions InvenTree/InvenTree/views.py
Expand Up @@ -8,8 +8,10 @@
import os

from django.conf import settings
from django.contrib.auth import password_validation
from django.contrib.auth.mixins import (LoginRequiredMixin,
PermissionRequiredMixin)
from django.core.exceptions import ValidationError
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
from django.shortcuts import redirect
from django.template.loader import render_to_string
Expand Down Expand Up @@ -560,8 +562,16 @@ def post(self, request, *args, **kwargs):
valid = False

if valid:
user.set_password(p1)
user.save()
try:
# Validate password
password_validation.validate_password(p1, user)

# Update the user
user.set_password(p1)
user.save()
except ValidationError as error:
form.add_error('confirm_password', str(error))
valid = False

return self.renderJsonResponse(request, form, data={'form_valid': valid})

Expand Down

0 comments on commit b9c9f5b

Please sign in to comment.