I have an assignment to create a password check that says if the password is strong (3 criteria checked off) moderate (2 criteria checked off) or weak (1 or less). The criteria are: 1: containing 2 of more digits 2: length is 6 or more characters 3: containing 1 or more special characters: ~ !@ #$%^&*.
I have tried a lot and looked up but wanted to import nothing, because thats not allowed at my exam. I want to use a for loop, if statements and a definition function. And want to keep it simple, im just a beginner.
password= str(input("What is the password? "))
specchar= ["!","~","@", "#", "$", "%", "^","&", "*"]
a=0
for item in specchar:
a= a+1
def CountDigitsFor(password):
res = []
for i in password:
if i.isdigit():
res.append(i)
return len(res)
def result(len(res), a)
return len(res)+a
b=0
if len(password)>=6:
b = b+1
if b == 1 and result == 3:
print("Password is strong")
if b+result == 3 or b+result ==2 :
print("Password is moderately strong")
if b+result <= 2:
print("Password is weak")
Nothing is the outcome except the user input. Could someone please help?
First, use more descriptive variable names than
aandb.Add a counter variable that counts the number of criteria that are satisfied.
You can use the built-in
sum()function to get the number of characters that meet a condition.