Guest User

Exercise 16.py

a guest
Feb 11th, 2018
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 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'''
  8.     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']
  9.     password = random.choice(passwordsList)
  10.     print(password)
  11.  
  12. def averagePassword(x):
  13.     '''Pick 1 word from each list and combine them with random number'''
  14.     adjectivesList = ['Super', 'Fancy', 'Crazy', 'Bald', 'Sneaky', 'Shiny', 'Stupid', 'Beautiful', 'Strong', 'Young', 'Dank']
  15.     animalsList = ['Cat', 'Dog', 'Horse', 'Dragon', 'Python', 'Lizard', 'Cow', 'Bull', 'Bee', 'Snake', 'Spider', 'Rabbit']
  16.     randomList = ['Trump', 'JackDaniels', 'Weed', 'Alcoholic', 'Minecraft', 'Obama', 'Xiaomi', 'Janusz', 'Wine', 'Pizza']
  17.     a = random.choice(adjectivesList)
  18.     b = random.choice(animalsList)
  19.     c = random.choice(randomList)
  20.     password = a + b + c + str(randint(1, 100))
  21.     print(password)
  22.  
  23. def strongPassword(x):
  24.     '''Generate random password'''
  25.     password = []
  26.     a = random.sample(string.ascii_letters, k = randint(3, 8)) #random letters
  27.     a = ''.join(a)
  28.     password.append(a)
  29.     b = random.sample(string.digits, k = randint(3, 8)) #random digits
  30.     b = ''.join(b)
  31.     password.append(b)
  32.     c = random.sample(string.punctuation, k = randint(3, 8)) #random symbols
  33.     c = ''.join(c)
  34.     password.append(c)
  35.     random.shuffle(password) #shuffle digits, symbols and letters order
  36.     password = ''.join(password)
  37.     print(password)
  38.  
  39. def chooseStrong():
  40.     '''Choose how strong password will be'''
  41.     choice = input('Do you want weak, average or strong password? w/a/s: ')
  42.     while True:
  43.         if choice == 'w':
  44.             p = print('Generated password is: ')
  45.             weakPassword(p)
  46.             newPassword()
  47.         if choice == 'a':
  48.             p = print('Generated password is: ')
  49.             averagePassword(p)
  50.             newPassword()
  51.         if choice == 's':
  52.             p = print('Generated password is: ')
  53.             strongPassword(p)
  54.             newPassword()
  55.         else:
  56.             choice = input("This is not correct answer! Please type 'w', 'a' or 's': ")
  57.  
  58. def newPassword():
  59.     '''Generate new password'''
  60.     choice = input('Do you want to generate new password? y/n: ')
  61.     while True:
  62.         if choice == 'y':
  63.             chooseStrong()
  64.         if choice == 'n':
  65.             quit()
  66.         else:
  67.             choice = input("This is not correct answer! Please type 'y' or 'n': ")
  68.  
  69. chooseStrong()
Add Comment
Please, Sign In to add comment