Guest User

Untitled

a guest
Feb 23rd, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. from random import randint
  2. import random, string
  3. '''Write a password generator in Python. Be creative with how you generate passwords - strong passwords have a mix of lowercase letters, uppercase letters, numbers, and symbols. The passwords should be random, generating a new password every time the user asks for a new password. Include your run-time code in a main method.
  4. Source: PracticePython.org - Exercise 16'''
  5.  
  6. def weakPassword(x):
  7. '''Pick random word from passwords list''' passwordsList = ['123456', '123456789', 'qwerty', '12345678', '111111', '1234567890', '1234567', 'password', '123123', '987654321', 'qwertyuiop', 'mynoob', '123321', '666666', '18atcskd2w', '7777777', '1q2w3e4r', '654321', '555555', '3rjs1la7qe', 'google', '1q2w3e4r5t', '123qwe', 'zxcvbnm', '1q2w3e']
  8. password = random.choice(passwordsList)
  9. print(password)
  10.  
  11. def averagePassword(x):
  12. '''Pick 1 word from each list and combine them with random number'''
  13. adjectivesList = ['Super', 'Fancy', 'Crazy', 'Bald', 'Sneaky', 'Shiny', 'Stupid', 'Beautiful', 'Strong', 'Young', 'Dank']
  14. animalsList = ['Cat', 'Dog', 'Horse', 'Dragon', 'Python', 'Lizard', 'Cow', 'Bull', 'Bee', 'Snake', 'Spider', 'Rabbit']
  15. randomList = ['Trump', 'JackDaniels', 'Weed', 'Alcoholic', 'Minecraft', 'Obama', 'Xiaomi', 'Janusz', 'Wine', 'Pizza']
  16. a = random.choice(adjectivesList)
  17. b = random.choice(animalsList)
  18. c = random.choice(randomList)
  19. password = a + b + c + str(randint(1, 100))
  20. print(password)
  21.  
  22. def strongPassword(x):
  23. '''Generate random password'''
  24. password = []
  25. a = random.sample(string.ascii_letters, k = randint(3, 8)) #random letters
  26. a = ''.join(a)
  27. password.append(a)
  28. b = random.sample(string.digits, k = randint(3, 8)) #random digits
  29. b = ''.join(b)
  30. password.append(b)
  31. c = random.sample(string.punctuation, k = randint(3, 8)) #random symbols
  32. c = ''.join(c)
  33. password.append(c)
  34. random.shuffle(password) #shuffle digits, symbols and letters order
  35. password = ''.join(password)
  36. print(password)
  37.  
  38. def chooseStrong():
  39. '''Choose how strong password will be'''
  40. choice = input('Do you want weak, average or strong password? w/a/s: ')
  41. while True:
  42. if choice == 'w':
  43. p = print('Generated password is: ')
  44. weakPassword(p)
  45. newPassword()
  46. if choice == 'a':
  47. p = print('Generated password is: ')
  48. averagePassword(p)
  49. newPassword()
  50. if choice == 's':
  51. p = print('Generated password is: ')
  52. strongPassword(p)
  53. newPassword()
  54. else:
  55. choice = input("This is not correct answer! Please type 'w', 'a' or 's': ")
  56.  
  57. def newPassword():
  58. '''Generate new password'''
  59. choice = input('Do you want to generate new password? y/n: ')
  60. while True:
  61. if choice == 'y':
  62. chooseStrong()
  63. if choice == 'n':
  64. quit()
  65. else:
  66. choice = input("This is not correct answer! Please type 'y' or 'n': ")
  67.  
  68. chooseStrong()
Add Comment
Please, Sign In to add comment