I am making a simple script in Python that evaluates the strength of a password on a score system that gives and takes points based on whether or not it contains upper or lowercase letters, numbers and symbols for school.
One of the requirements is that it checks for 3 letters or numbers that are consecutive from left to right on a UK QWERTY keyboard and takes away 5 points for each instance. For example the password 'qwer123' would lose 15 points for 'qwe', 'wer' and '123'. How could this be accomplished? My current code below.
def check():
user_password_score=0
password_capitals=False
password_lowers=False
password_numbers=False
password_symbols=False
password_explanation_check=False
ascii_codes=[]
password_explanation=[]
print("The only characters allowed in the passwords are upper and lower case letters, numbers and these symbols; !, $, %, ^, &, *, (, ), _, -, = and +.\n")
user_password=str(input("Enter the password you would like to get checked: "))
print("")
if len(user_password)>24 or len(user_password)<8:
print("That password is not between 8 and 24 characters and so the Password Checker can't evaluate it.")
menu()
for i in user_password:
ascii_code=ord(i)
#print(ascii_code)
ascii_codes.append(ascii_code)
#print(ascii_codes)
for i in range(len(ascii_codes)):
if ascii_codes[i]>64 and ascii_codes[i]<90:
password_capitals=True
elif ascii_codes[i]>96 and ascii_codes[i]<123:
password_lowers=True
elif ascii_codes[i]>47 and ascii_codes[i]<58:
password_numbers=True
elif ascii_codes[i] in (33,36,37,94,38,42,40,41,45,95,61,43):
password_symbols=True
else:
print("Your password contains characters that aren't allowed.\n")
menu()
if password_capitals==True:
user_password_score+=5
if password_lowers==True:
user_password_score+=5
if password_numbers==True:
user_password_score+=5
if password_symbols==True:
user_password_score+=5
if password_capitals==True and password_lowers==True and password_numbers==True and password_symbols==True:
user_password_score+=10
if password_numbers==False and password_symbols==False:
user_password_score-=5
if password_capitals==False and password_lowers==False and password_symbols==False:
user_password_score-=5
if password_capitals==False and password_lowers==False and password_numbers==False:
user_password_score-=5
#print(user_password_score)
if user_password_score>20:
print("Your password is strong.\n")
else:
print("That password is weak.\n")
#don't forget you still need to add the thing that checks for 'qwe' and other stuff.
menu()