Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #program GCSE coursework
- #author Louis Rinaldo
- allowed=set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!$%^&*()-_=+")
- lower=("abcdefghijklmnopqrstuvwxyz")
- upper=("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
- digit=("0123456789")
- symbol=("!$%^&*()-_=+")
- import random
- # clear screen
- def cls():
- print("\n"*60)
- # introduction
- def intro():
- cls()
- print("""\t\t --- Password Checker and Generator ---
- \n\n\n\nThis program will judge the strength of an inputted password or generate a strong one.""")
- menu()
- # recurring menu
- def menu():
- print("""\n\n\n Please select an option:
- \t1 - Check Password
- \t2 - Generate Password
- \t3 - Quit""")
- option = input()
- while len(option) == 0:
- option = input("\nPlease select 1, 2 or 3")
- invalid = True
- while invalid == True:
- if option[0].upper() == "C" or option == "1":
- invalid = False
- checker()
- elif option[0].upper() == "G" or option == "2":
- invalid = False
- generator()
- elif option[0].upper() == "Q" or option == "3":
- invalid = False
- quitter()
- else:
- option = input("\nPlease select 1, 2 or 3")
- while len(option) == 0:
- option = input("\nPlease select 1, 2 or 3")
- invalid = False
- # checker interface
- def checker():
- password=input("\n\nPlease enter a password that you want checking; it may contain letters, numbers and a few allowed characters:")
- length=len(password)
- while length == 0:
- password = input("\nPlease enter a password:")
- length = len(password)
- if length < 8 and length != 0:
- input("""\nThe entered password it too short. It must contain at least 8 characters.
- \nPress <Enter> to return to menu.""")
- cls()
- menu()
- if length > 24:
- input("""/nThe entered password is too long. It must not contain more than 25 characters.
- \nPress <Enter> to return to menu.""")
- cls()
- menu()
- elif length > 7 and length < 25:
- if password and allowed.issuperset(password):
- score = char_check(password)
- score = triplecheck(password, score)
- print("\n\nYour password score is",score)
- if score > 20:
- print("\nYour password strength is strong!")
- elif score <= 0:
- print("\nYour password strength is weak!")
- else:
- print("\nYour password strength is medium...")
- input("\n\nPress <Enter> to return to menu.")
- cls()
- menu()
- else:
- input("""\nThe entered password contains disallowed characters.
- Allowed characters are ! $ % ^ & * ( ) - _ = . +
- No spaces allowed.
- \n\nPress <Enter> to return to menu.""")
- cls()
- menu()
- # generates a password
- def generator():
- print("\nThis is password generator...")
- input("\nPress <Enter> to generate a password")
- strong = False
- while strong == False:
- lenpassword = random.randint(8,12)
- possible = lower + upper + digit + symbol
- password = ''.join(random.choice(possible) for x in range(lenpassword))
- score=char_check(password)
- score=triplecheck(password, score)
- if score > 20:
- strong = True
- print("\n\nThe generated password is:",password)
- print("\nThe score for this password is:",score)
- print("\nThis is a strong password!")
- input("\n\nPress <Enter> to return to menu.")
- cls()
- menu()
- # calculates score for type of character
- def char_check(password):
- lower_inside= True
- upper_inside = True
- digit_inside = True
- symbol_inside = True
- score = 0
- score = len(password)
- for i in password:
- # if contains lowercase letter
- if i in lower and lower_inside == True:
- lower_inside = False
- score = score + 5
- # if contains uppercase letter
- if i in upper and upper_inside == True:
- upper_inside = False
- score = score + 5
- # if contains number
- if i in digit and digit_inside == True:
- digit_inside = False
- score = score + 5
- # if contains symbol
- if i in symbol and symbol_inside == True:
- symbol_inside = False
- score = score + 5
- # if contains one of everything
- if lower_inside == False and upper_inside == False and digit_inside == False and symbol_inside == False:
- score = score + 10
- # if only contains letters
- if password.isalpha() == True:
- score = score - 5
- # if only contains numbers
- if password.isnumeric() == True:
- score = score - 5
- # if only contains symbols
- if lower_inside == True and upper_inside == True and digit_inside == True:
- score=score-5
- return score
- # checks for 3 letters in a row and deducts 5 points every time
- def triplecheck(password, score):
- row1 = "qwertyuiop"
- row2 = "asdfghjkl"
- row3 = "zxcvbnm"
- password=password.lower()
- for i in range(0,len(password)-2):
- substring = password[i]+password[i+1]+password[i+2]
- if substring in row1 or substring in row2 or substring in row3:
- score = score - 5
- return score
- # quits/ends program
- def quitter():
- input("\nPress <Enter> to quit")
- cls()
- # main program
- intro()
Add Comment
Please, Sign In to add comment