From 85f273b7260cc103644e34a3a549a8a975944f58 Mon Sep 17 00:00:00 2001 From: starnakin Date: Tue, 24 Oct 2023 22:56:37 +0200 Subject: [PATCH] fix: use variable to len --- django/trancendence/accounts/settings.py | 4 ++++ django/trancendence/accounts/views.py | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 django/trancendence/accounts/settings.py diff --git a/django/trancendence/accounts/settings.py b/django/trancendence/accounts/settings.py new file mode 100644 index 0000000..2e72297 --- /dev/null +++ b/django/trancendence/accounts/settings.py @@ -0,0 +1,4 @@ +PASSWORD_MIN_SIZE = 3 +PASSWORD_MAX_SIZE = 128 +USERNAME_MIN_SIZE = 3 +USERNAME_MAX_SIZE = 40 \ No newline at end of file diff --git a/django/trancendence/accounts/views.py b/django/trancendence/accounts/views.py index 69e6485..78f34c5 100644 --- a/django/trancendence/accounts/views.py +++ b/django/trancendence/accounts/views.py @@ -7,6 +7,7 @@ from django.contrib.auth.models import User from django.db.models.query import QuerySet from .status_code import * +from .settings import * class Login(View): def get(self, request): @@ -37,10 +38,10 @@ class Register(View): def post(self, request): password = request.POST.get("password") - if (password == None or len(password) < 3): + if (password == None or not PASSWORD_MAX_SIZE >= len(password) >= PASSWORD_MIN_SIZE): return HttpResponse(INVALID_PASSWORD) username = request.POST.get("username") - if (username == None or len(username) < 3): + if (username == None or not USERNAME_MAX_SIZE >= len(username) >= USERNAME_MIN_SIZE): return HttpResponse(INVALID_USERNAME) if User.objects.filter(username=username).exists(): @@ -98,7 +99,7 @@ class ChangePassword(View): return HttpResponse(INVALID_USERNAME_PASSWORD) new_password = request.POST.get("new_password") - if (new_password == None or len(new_password) < 3): + if (new_password == None or not PASSWORD_MAX_SIZE >= len(new_password) >= PASSWORD_MIN_SIZE): return HttpResponse(INVALID_PASSWORD) user.set_password(new_password)