Update check.py

This commit is contained in:
Daniel
2023-01-08 02:20:01 +02:00
committed by GitHub
parent de93bdd08e
commit 9d1d50a9b1

View File

@@ -1,3 +1,4 @@
from numpy import ceil
def checkLength(psw): def checkLength(psw):
if 20 >= len(psw) >= 8: if 20 >= len(psw) >= 8:
return 0 return 0
@@ -9,13 +10,17 @@ def checkLength(psw):
def checkRepeating(psw): def checkRepeating(psw):
steps = 0 steps = 0
tempSteps = 1 tempSteps = 1
while len(psw) > 1: while len(psw) > 0:
x = psw[0] x = psw[0]
if psw[1] == x: if len(psw) > 1:
tempSteps += 1
psw = psw[1:] psw = psw[1:]
elif len(psw) == 1:
break
if psw[0] == x:
tempSteps += 1
if tempSteps > 2:
steps += 1
else: else:
steps = tempSteps - 2 + steps if tempSteps > 2 else steps
tempSteps = 1 tempSteps = 1
psw = psw[1:] psw = psw[1:]
return steps return steps
@@ -24,9 +29,12 @@ def checkRepeating(psw):
def checkComposition(psw): def checkComposition(psw):
values = [0, 0, 0, 0] values = [0, 0, 0, 0]
for x in psw: for x in psw:
values[0] = 1 if x.islower() else values[0] if x.islower():
values[1] = 1 if x.upper() else values[1] values[0] = 1
values[2] = 1 if x.isnumeric() else values[2] if x.isnumeric():
values[1] = 1
if x.isupper():
values[2] = 1
if x in ['@', '_', '!', '#', '$', '%', '^', '&', '*', '(', ')', '<', '>', '?', '/', '\'', '|', '}', '{', '~', if x in ['@', '_', '!', '#', '$', '%', '^', '&', '*', '(', ')', '<', '>', '?', '/', '\'', '|', '}', '{', '~',
':', '-']: ':', '-']:
values[3] = 1 values[3] = 1
@@ -34,11 +42,24 @@ def checkComposition(psw):
def checkPassword(psw): def checkPassword(psw):
x = max(checkLength(psw), checkComposition(psw), checkRepeating(psw)) extraSteps = 0
if x: a = checkComposition(psw)
return x b = checkLength(psw)
return "Good!" c = checkRepeating(psw)
if len(psw) < 8:
return 8 - len(psw)
if c > 20:
extraSteps += c - 20
if a == 0 and b == 0 and c == 0:
return "good"
if a == 0 and b == 0:
return c
else:
return max(a, int(ceil((c+extraSteps+b)/3)))
return "good"
passw = "aaaaaaaaaaaaaaaaaaaaaa"
passw = input()
print(checkPassword(passw)) print(checkPassword(passw))
print(checkLength(passw))
print(checkRepeating(passw))
print(checkComposition(passw))