Advertisement
Guest User

Untitled

a guest
Nov 30th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. import random
  2. def print_menu():
  3. print( 30 * "-" , "MENU" , 30 * "-")
  4. print("1. Check password strength")
  5. print("2. Generate an ideal password")
  6. print("3. Quit")
  7. print( 67 * "-")
  8.  
  9. def genpass():
  10. alphabet = "abcdefghijklmnopqrstuvwxyz"
  11. symbols = "!$%^&*()-_=+"
  12. upperalphabet = alphabet.upper()
  13. pw_len = 12
  14. pwlist = []
  15.  
  16. for i in range(pw_len//3):
  17. pwlist.append(alphabet[random.randrange(len(alphabet))])
  18. pwlist.append(symbols[random.randrange(len(symbols))])
  19. pwlist.append(upperalphabet[random.randrange(len(upperalphabet))])
  20. pwlist.append(str(random.randrange(10)))
  21. for i in range(pw_len-len(pwlist)):
  22. pwlist.append(alphabet[random.randrange(len(alphabet))])
  23. random.shuffle(pwlist)
  24. pwstring = "".join(pwlist)
  25. print(pwstring)
  26.  
  27. def passcheck():
  28. password_user = input("Input password : ")
  29. score = 0
  30. if len(password_user) <=5:
  31. print("Password is too short! ")
  32. score = 1
  33. elif password_user == password_user.lower():
  34. print("Bad Password")
  35. score = 1
  36. elif password_user == password_user.upper():
  37. print("Bad Password")
  38. score = 1
  39. else:
  40. while score == 0:
  41. for x in range(33,48):
  42. ascii_str = chr(x)
  43. if password_user.find(ascii_str) >= 0:
  44. score = score + 3
  45. for y in range(97,123):
  46. ascii_lower = chr(y)
  47. if password_user.find(ascii_lower) >= 0:
  48. score = score + 1
  49. for w in range(65,91):
  50. ascii_upper = chr(w)
  51. if password_user.find(ascii_upper) >= 0:
  52. score = score + 2
  53. for z in range(48,58):
  54. ascii_num = chr(z)
  55. if password_user.find(ascii_num) >= 0:
  56. score = score + 2
  57. if score >0 | score <=5:
  58. print("Weak Password")
  59. print(score)
  60. elif score > 5 | score < 7:
  61. print("Medium Password")
  62. print(score)
  63. elif score >= 7:
  64. print("Strong Password")
  65. print(score)
  66.  
  67. loop=True
  68.  
  69. while loop:
  70. print_menu()
  71. choice = input("Enter your choice [1-3]:")
  72.  
  73. if choice==("1"):
  74. print("You have chosen to check your password strenth")
  75. loop=False
  76. passcheck()
  77.  
  78. elif choice==("2"):
  79. print("You have chosen to generate an ideal password")
  80. loop=False
  81. genpass()
  82.  
  83.  
  84. elif choice==("3"):
  85. print("You have chosen to exit")
  86. loop=False
  87. else:
  88. input("Wrong selection. Enter a number between 1 and 3")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement