Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 KB | None | 0 0
  1. import random
  2. while True:
  3. def Check_password(password):
  4. global strength, score #Makes the varirable "strength" and "score" accessable to the entire program
  5. while len(password) < 8 or len(password) > 24:
  6. print('Please re-enter password and make sure your password is between 8 and 24 characters\n')
  7. Menu()
  8. score = len(password)
  9. password_array = list(password) #Putting password into a array
  10. password_ascii = list()
  11. for i in range (len(password)):#For loop assigning ascii values of password into a array
  12. password_ascii.append(ord(password[i]))
  13. capital_letter = False
  14. lowercase_letter = False
  15. number = False
  16. symbol = False
  17. for i in range (len(password)):
  18. if password_ascii[i] >= 65 and password_ascii[i] <= 90:#Checking for capital letters using ascii
  19. capital_letter = True
  20. if password_ascii[i] >= 97 and password_ascii[i] <= 122:#Checking for lowercase letters using ascii
  21. lowercase_letter = True
  22. if password_ascii[i] >= 48 and password_ascii[i] <= 57:#Checking for numbers 0-9 using ascii
  23. number = True
  24. if password_ascii[i] == 33 or password_ascii[i] == 45 or password_ascii[i] == 61:#Checking for symbols using ascii
  25. symbol = True
  26. if password_ascii[i] >= 36 and password_ascii[i] <= 38:
  27. symbol = True
  28. if password_ascii[i] >= 40 and password_ascii[i] <= 43:
  29. symbol = True
  30. if password_ascii[i] == 94 or password_ascii[i] == 95:
  31. symbol = True
  32. if capital_letter == False and lowercase_letter == False and number == False and symbol == False:#Checking that the password only contains valid character
  33. print('You entered an invalid character\n You will be returned to the menu')
  34. Menu()
  35. #Checking for QWERTY
  36. password_lowercase = password.lower() # Puts password into all lowercsse
  37.  
  38. #Checking foe the first row of qwerty
  39. qwerty_1st = "qwertyuiop"
  40. for i in range(0, len(password_lowercase) - 2):
  41. check = password_lowercase[i:i + 3]
  42. if check in qwerty_1st:
  43. score -= 5
  44.  
  45. #Checking for the second row of qwerty
  46. qwerty_2nd = "asdfghjkl"
  47. for i in range(0, len(password_lowercase) - 2):
  48. check = password_lowercase[i:i + 3]
  49. if check in qwerty_2nd:
  50. score -= 5
  51.  
  52. #Checking for the third row of qwerty
  53. qwerty_3rd = "zxcvbnm"
  54. for i in range(0, len(password_lowercase) - 2):
  55. check = password_lowercase[i:i + 3]
  56. if check in qwerty_3rd:
  57. score -= 5
  58.  
  59. #Adding up the score from the checks
  60. if capital_letter == True:#Adding 5 points to the password if at least on capital letter
  61. score += 5
  62. if lowercase_letter == True:#Adding 5 points to the password if lowercase letters are present
  63. score += 5
  64. if number == True:#Adding up the score if numbers are in the password
  65. score += 5
  66. if symbol == True:#Adding 5 points if the allowed symbols are in the password
  67. score += 5
  68. if capital_letter == True and lowercase_letter == True and number == True and symbol == True:#Adding 10 points if the password contains capital letter
  69. score += 10
  70. if capital_letter == True or lowercase_letter == True and number == False and symbol == False:#Taking 5 points if it only conaints capital and lowercase letters
  71. score -= 5
  72. elif capital_letter == False and lowercase_letter == False and number == True and symbol == False:#Taking 5 points if it only have numbers in
  73. score -= 5
  74. elif capital_letter == False and lowercase_letter == False and number == False and symbol == True:#Taking 5 points if it only has symbols in
  75. score -= 5
  76. #Determining the passwords strength
  77. strength = ''
  78. if score > 20:
  79. strength = 'Strong'
  80. elif score <= 0:
  81. strength = 'Weak'
  82. else:
  83. strength = 'Medium'
  84. print('Your password,',password+', has a strength of:',strength,'\nYou will now be returned to the menu')
  85. Menu()
  86.  
  87. def Generate_password():
  88. global score #Makes variable "score" accessable to the whole program
  89. length = random.randint(9,24)
  90. password_generated_array = [None]*length
  91. characters = [['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'], #Multidimensional array containing all characters
  92. ['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'], #needed for the password generation
  93. ['0','1','2','3','4','5','6','7','8','9'],
  94. ['!','$','%','^','&','*','(',')','-','_','=','+']]
  95. for i in range (length): #For loop to assign each character to the password array
  96. character_choice = random.randint(0,len(characters))
  97. character_choice_2 = random.randint(0,len(characters[character_choice - 1]))
  98. password_generated_array[i] = characters[character_choice - 1][character_choice_2 - 1]
  99. password_generated = ''.join(password_generated_array) #Converting the array back into a string
  100. Check_password(password_generated)
  101.  
  102. def Menu():
  103. print('Please selection on of the following options:')
  104. option = int(input("**********************\n1. Check Password\n2. Generate password\n3. Quit\n**********************\n"))
  105. if option == 1:
  106. password = input('Please enter your password\n')
  107. Check_password(password)
  108. elif option == 2:
  109. Generate_password()
  110. elif option == 3:
  111. quit()
  112. Menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement