Guest User

Untitled

a guest
Dec 12th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 KB | None | 0 0
  1. #Password Strength
  2. #Copyright 2017 nihad ali
  3. def checkPass(password, pre_pass):
  4. length = int()
  5. lower = int()
  6. upper = int()
  7. special = int()
  8. number = int()
  9. like_past = int()
  10. f_name = int()
  11. s_name = int()
  12. password_strength = 0
  13. if len(password)>=8 :
  14. length = 1
  15. for i in lower_alphabet:
  16. if i in password:
  17. lower = 1
  18. for i in upper_alphabet:
  19. if i in password:
  20. upper = 1
  21. for i in special_characters:
  22. if i in password:
  23. special = 1
  24. for i in numbers:
  25. if i in password:
  26. number = 1
  27. if pre_pass.lower() not in password.lower():
  28. like_past = 1
  29.  
  30. if length == 1:
  31. password_strength += 1
  32. if lower == 1 :
  33. password_strength += 1
  34. if upper== 1 :
  35. password_strength += 1
  36. if special == 1:
  37. password_strength +=2
  38. if f_name != 1:
  39. password_strength -=2
  40. if s_name != 1:
  41. password_strength -=2
  42. if like_past != 1:
  43. password_strength -=1
  44.  
  45. password_rank = str()
  46.  
  47. if password_strength >= 5:
  48. password_rank = 'Very Strong'
  49. elif password_strength == 4:
  50. password_rank = 'Strong'
  51. elif password_strength == 3:
  52. password_rank = 'OK'
  53. elif password_strength == 2:
  54. password_rank = 'Not Good'
  55. elif password_strength ==1:
  56. password_rank = 'Bad'
  57. elif password_strength < 1:
  58. password_rank = 'very bad'
  59. print('\nI think that your password is ',password_rank)
  60. issues = [length, lower, upper, special, number, like_past, f_name, s_name, password_rank]
  61. return issues
  62.  
  63. lower_alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  64. upper_alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
  65. numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
  66. special_characters = [' ', '!', '#', '$', '%', '&', '"', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~',"'"]
  67.  
  68. choice = None
  69.  
  70. print("""
  71. Welcome to Nihad's password strength tester
  72. """)
  73.  
  74. while choice != '0':
  75. print("""
  76. Menu options:
  77. 1 - Password Generator
  78. 2 - Check Password Strength
  79. 3 - quit
  80.  
  81.  
  82.  
  83. """)
  84. choice = str(input('Please type the number that is beside your choice and press enter: '))
  85. if choice == '1':
  86. password = input('\nPlease enter your password here: ')
  87. pre_pass = input('\nPlease enter your old password here: ')
  88. issues = checkPass(password,pre_pass)
  89. why = input('\nIf you would like to find out why type why? and press enter: ')
  90. if why.lower() == 'why?':
  91. if issues[0] != 1:
  92. print("It's too short")
  93. if issues[1] != 1:
  94. print("It doesn't have a lower case character in it")
  95. if issues[2] != 1:
  96. print("It doesn't have an upper case character in it")
  97. if issues[3] != 1:
  98. print("It doesn't have a special character in it")
  99. if issues[4] != 1:
  100. print("It doesn't have a number in it")
  101. if issues[5] != 1:
  102. print("It's like your old password")
  103. if issues[6] != 1:
  104. print("It's got your first name in it")
  105. if issues[7] != 1:
  106. print("It's got your last name in it")
  107. if issues[8] == 'Very Strong':
  108. print('There is nothing wrong with it!')
  109. elif choice == '0':
  110. print('Check your password strength here')
  111. else:
  112. print('Goodbye')
  113. from sys import exit
  114.  
  115. def check_upper(input):
  116. uppers = 0
  117. upper_list = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split()
  118. for char in input:
  119. if char in upper_list:
  120. uppers += 1
  121. if uppers > 0:
  122. return True
  123. else:
  124. return False
  125.  
  126. def check_lower(input):
  127. lowers = 0
  128. lower_list = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split()
  129. for char in input:
  130. if char in lower_list:
  131. lowers += 1
  132. if lowers > 0:
  133. return True
  134. else:
  135. return False
  136.  
  137. def check_number(input):
  138. numbers = 0
  139. number_list = "1 2 3 4 5 6 7 8 9 0".split()
  140. for char in input:
  141. if char in number_list:
  142. numbers += 1
  143. if numbers > 0:
  144. return True
  145. else:
  146. return False
  147.  
  148. def check_special(input):
  149. specials = 0
  150. special_list = "! @ $ % ^ & * ( ) _ - + = { } [ ] | \ , . > < / ? ~ ` \" ' : ;".split()
  151. for char in input:
  152. if char in special_list:
  153. specials += 1
  154. if specials > 0:
  155. return True
  156. else:
  157. return False
  158.  
  159. def check_len(input):
  160. if len(input) >= 8:
  161. return True
  162. else:
  163. return False
  164.  
  165.  
  166. def validate_password(input):
  167. check_dict = {
  168. 'upper': check_upper(input),
  169. 'lower': check_lower(input),
  170. 'number': check_number(input),
  171. 'special': check_special(input),
  172. 'len' : check_len(input)
  173. }
  174. if check_upper(input) & check_lower(input) & check_number(input) & check_special(input) & check_len(input):
  175. return True
  176. else:
  177. print ("Invalid password! Review below and change your password accordingly!")
  178. print
  179. if check_dict['upper'] == False:
  180. print ("Password needs at least one upper-case character.")
  181. if check_dict['lower'] == False:
  182. print ("Password needs at least one lower-case character.")
  183. if check_dict['number'] == False:
  184. print ("Password needs at least one number.")
  185. if check_dict['special'] == False:
  186. print ("Password needs at least one special character.")
  187. if check_dict['len'] == False:
  188. print ("Password needs to be at least 8 characters in length.")
  189. print
  190.  
  191. while True:
  192. password = input ("Enter desired password: ")
  193. print
  194. if validate_password(password):
  195. print ("Password meets all requirements and may be used.")
  196. print
  197. print ("Exiting program...")
  198. print
  199. exit(0)
Add Comment
Please, Sign In to add comment