Guest User

Untitled

a guest
Mar 28th, 2018
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. #program GCSE coursework
  2. #author Louis Rinaldo
  3.  
  4. allowed=set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!$%^&*()-_=+")
  5. lower=("abcdefghijklmnopqrstuvwxyz")
  6. upper=("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  7. digit=("0123456789")
  8. symbol=("!$%^&*()-_=+")
  9.  
  10. import random
  11.  
  12.  
  13. # clear screen
  14. def cls():
  15. print("\n"*60)
  16.  
  17.  
  18. # introduction
  19. def intro():
  20. cls()
  21. print("""\t\t --- Password Checker and Generator ---
  22. \n\n\n\nThis program will judge the strength of an inputted password or generate a strong one.""")
  23. menu()
  24.  
  25.  
  26. # recurring menu
  27. def menu():
  28. print("""\n\n\n Please select an option:
  29.  
  30. \t1 - Check Password
  31.  
  32. \t2 - Generate Password
  33.  
  34. \t3 - Quit""")
  35.  
  36. option = input()
  37.  
  38. while len(option) == 0:
  39. option = input("\nPlease select 1, 2 or 3")
  40.  
  41.  
  42. invalid = True
  43.  
  44. while invalid == True:
  45.  
  46. if option[0].upper() == "C" or option == "1":
  47. invalid = False
  48. checker()
  49.  
  50. elif option[0].upper() == "G" or option == "2":
  51. invalid = False
  52. generator()
  53.  
  54. elif option[0].upper() == "Q" or option == "3":
  55. invalid = False
  56. quitter()
  57.  
  58. else:
  59. option = input("\nPlease select 1, 2 or 3")
  60.  
  61. while len(option) == 0:
  62. option = input("\nPlease select 1, 2 or 3")
  63.  
  64. invalid = False
  65.  
  66.  
  67.  
  68. # checker interface
  69.  
  70. def checker():
  71. password=input("\n\nPlease enter a password that you want checking; it may contain letters, numbers and a few allowed characters:")
  72.  
  73. length=len(password)
  74.  
  75.  
  76. while length == 0:
  77. password = input("\nPlease enter a password:")
  78. length = len(password)
  79.  
  80.  
  81. if length < 8 and length != 0:
  82. input("""\nThe entered password it too short. It must contain at least 8 characters.
  83. \nPress <Enter> to return to menu.""")
  84. cls()
  85. menu()
  86.  
  87.  
  88. if length > 24:
  89. input("""/nThe entered password is too long. It must not contain more than 25 characters.
  90. \nPress <Enter> to return to menu.""")
  91. cls()
  92. menu()
  93.  
  94.  
  95. elif length > 7 and length < 25:
  96.  
  97. if password and allowed.issuperset(password):
  98.  
  99.  
  100. score = char_check(password)
  101. score = triplecheck(password, score)
  102.  
  103. print("\n\nYour password score is",score)
  104.  
  105.  
  106. if score > 20:
  107. print("\nYour password strength is strong!")
  108.  
  109. elif score <= 0:
  110. print("\nYour password strength is weak!")
  111.  
  112. else:
  113. print("\nYour password strength is medium...")
  114.  
  115.  
  116. input("\n\nPress <Enter> to return to menu.")
  117.  
  118. cls()
  119.  
  120. menu()
  121.  
  122.  
  123. else:
  124. input("""\nThe entered password contains disallowed characters.
  125. Allowed characters are ! $ % ^ & * ( ) - _ = . +
  126. No spaces allowed.
  127. \n\nPress <Enter> to return to menu.""")
  128. cls()
  129. menu()
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. # generates a password
  138.  
  139. def generator():
  140.  
  141. print("\nThis is password generator...")
  142. input("\nPress <Enter> to generate a password")
  143.  
  144. strong = False
  145.  
  146. while strong == False:
  147.  
  148. lenpassword = random.randint(8,12)
  149. possible = lower + upper + digit + symbol
  150. password = ''.join(random.choice(possible) for x in range(lenpassword))
  151.  
  152. score=char_check(password)
  153.  
  154. score=triplecheck(password, score)
  155.  
  156.  
  157. if score > 20:
  158. strong = True
  159. print("\n\nThe generated password is:",password)
  160. print("\nThe score for this password is:",score)
  161. print("\nThis is a strong password!")
  162.  
  163.  
  164. input("\n\nPress <Enter> to return to menu.")
  165. cls()
  166. menu()
  167.  
  168.  
  169.  
  170.  
  171. # calculates score for type of character
  172.  
  173. def char_check(password):
  174.  
  175. lower_inside= True
  176. upper_inside = True
  177. digit_inside = True
  178. symbol_inside = True
  179.  
  180.  
  181.  
  182. score = 0
  183. score = len(password)
  184.  
  185.  
  186. for i in password:
  187.  
  188.  
  189. # if contains lowercase letter
  190.  
  191. if i in lower and lower_inside == True:
  192. lower_inside = False
  193. score = score + 5
  194.  
  195.  
  196. # if contains uppercase letter
  197.  
  198. if i in upper and upper_inside == True:
  199. upper_inside = False
  200. score = score + 5
  201.  
  202.  
  203. # if contains number
  204.  
  205. if i in digit and digit_inside == True:
  206. digit_inside = False
  207. score = score + 5
  208.  
  209.  
  210. # if contains symbol
  211.  
  212. if i in symbol and symbol_inside == True:
  213. symbol_inside = False
  214. score = score + 5
  215.  
  216.  
  217. # if contains one of everything
  218.  
  219. if lower_inside == False and upper_inside == False and digit_inside == False and symbol_inside == False:
  220. score = score + 10
  221.  
  222.  
  223. # if only contains letters
  224.  
  225. if password.isalpha() == True:
  226. score = score - 5
  227.  
  228.  
  229. # if only contains numbers
  230.  
  231. if password.isnumeric() == True:
  232. score = score - 5
  233.  
  234.  
  235. # if only contains symbols
  236.  
  237. if lower_inside == True and upper_inside == True and digit_inside == True:
  238. score=score-5
  239.  
  240.  
  241. return score
  242.  
  243.  
  244.  
  245.  
  246. # checks for 3 letters in a row and deducts 5 points every time
  247.  
  248. def triplecheck(password, score):
  249.  
  250. row1 = "qwertyuiop"
  251. row2 = "asdfghjkl"
  252. row3 = "zxcvbnm"
  253.  
  254. password=password.lower()
  255.  
  256. for i in range(0,len(password)-2):
  257. substring = password[i]+password[i+1]+password[i+2]
  258.  
  259. if substring in row1 or substring in row2 or substring in row3:
  260. score = score - 5
  261.  
  262. return score
  263.  
  264.  
  265.  
  266. # quits/ends program
  267.  
  268. def quitter():
  269.  
  270. input("\nPress <Enter> to quit")
  271. cls()
  272.  
  273.  
  274.  
  275. # main program
  276.  
  277. intro()
Add Comment
Please, Sign In to add comment