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