From 9d1d50a9b15d7b469ca5c3d1e2a591b18efd0335 Mon Sep 17 00:00:00 2001 From: Daniel <59575049+lemoentjiez@users.noreply.github.com> Date: Sun, 8 Jan 2023 02:20:01 +0200 Subject: [PATCH] Update check.py --- LabMD_2/check.py | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/LabMD_2/check.py b/LabMD_2/check.py index 1a4f1e2..8420d5b 100644 --- a/LabMD_2/check.py +++ b/LabMD_2/check.py @@ -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))