fix: use variable to len

This commit is contained in:
starnakin 2023-10-24 22:56:37 +02:00
parent d469466e66
commit 85f273b726
2 changed files with 8 additions and 3 deletions

View File

@ -0,0 +1,4 @@
PASSWORD_MIN_SIZE = 3
PASSWORD_MAX_SIZE = 128
USERNAME_MIN_SIZE = 3
USERNAME_MAX_SIZE = 40

View File

@ -7,6 +7,7 @@ from django.contrib.auth.models import User
from django.db.models.query import QuerySet from django.db.models.query import QuerySet
from .status_code import * from .status_code import *
from .settings import *
class Login(View): class Login(View):
def get(self, request): def get(self, request):
@ -37,10 +38,10 @@ class Register(View):
def post(self, request): def post(self, request):
password = request.POST.get("password") 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) return HttpResponse(INVALID_PASSWORD)
username = request.POST.get("username") 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) return HttpResponse(INVALID_USERNAME)
if User.objects.filter(username=username).exists(): if User.objects.filter(username=username).exists():
@ -98,7 +99,7 @@ class ChangePassword(View):
return HttpResponse(INVALID_USERNAME_PASSWORD) return HttpResponse(INVALID_USERNAME_PASSWORD)
new_password = request.POST.get("new_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) return HttpResponse(INVALID_PASSWORD)
user.set_password(new_password) user.set_password(new_password)