Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. ##Write a password generator in Python. Ask the user how strong they want their
  2. ##passport to be. Be creative with how you generate passwords - strong
  3. ##passwords have a mix of lowercase letters, uppercase letters, numbers,
  4. ##and symbols. The passwords should be random, generating a new password
  5. ##every time the user asks for a new password. Include your run-time code
  6. ##in a main method.
  7.  
  8. import random
  9.  
  10. #There are 3 lists, each adding a level of strength to the password
  11. letter_mix = list("qwertyuiopasdfghjklzxcvbnm")
  12. letter2_mix = list("QWERTYUIOPASDFGHJKLZXCVBNM")
  13. symbol_mix = list("1234567890`+,.-^*<>;:_'?")
  14. merged_list = letter_mix + letter2_mix
  15. merged_list2 = merged_list + symbol_mix
  16.  
  17. human = input("How long do you want your passport to be? (4-9)")
  18.  
  19. def password_generator(x):
  20. human2 = raw_input("How strong do you want your passport to be? (strong/medium/weak)")
  21. if human2 == "weak":
  22. list_random = random.sample(letter_mix, x)
  23. list2 = ''.join(list_random)
  24. print list2
  25. elif human2 == "medium":
  26. list_random = random.sample(merged_list, x)
  27. list2 = ''.join(list_random)
  28. print list2
  29. elif human2 == "strong":
  30. list_random = random.sample(merged_list2, x)
  31. list2 = ''.join(list_random)
  32. print list2
  33. else:
  34. print "Sorry, that was not one of the options. Please tape either 'weak', 'medium' or 'strong'"
  35.  
  36. continuar = raw_input("Do you want to generate another passport? (y/n)")
  37. if continuar == "y":
  38. b = True
  39. elif continuar == "n":
  40. b = False
  41. print "See you soon"
  42. else:
  43. print "Sorry, that was not one of the options"
  44.  
  45.  
  46.  
  47. password_generator(human)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement