Advertisement
Guest User

Exercise 16.py

a guest
Feb 11th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. import random, string
  2. from random import randint
  3.  
  4. def weakPassword(r):
  5.     '''Pick random word from passwords list'''
  6.     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']
  7.     r = random.choice(passwordsList)
  8.     print(r)
  9.  
  10. def strongPassword(r):
  11.     '''Generate random password'''
  12.     password = []
  13.     a = random.sample(string.ascii_letters, k = randint(3, 8)) #random letters
  14.     a = ''.join(a)
  15.     password.append(a)
  16.     b = random.sample(string.digits, k = randint(3, 8)) #random digits
  17.     b = ''.join(b)
  18.     password.append(b)
  19.     c = random.sample(string.punctuation, k = randint(3, 8)) #random symbols
  20.     c = ''.join(c)
  21.     password.append(c)
  22.     random.shuffle(password) #shuffle digits, symbols and letters order
  23.     password = ''.join(password)
  24.     print(password)
  25.  
  26. def strongOrWeak():
  27.     '''Choose how strong password will be'''
  28.     choice = input('Do you want strong or weak password? w/s: ')
  29.     while True:
  30.         if choice == 'w':
  31.             p = print('Generated password is: ')
  32.             weakPassword(p)
  33.             newPassword()
  34.         if choice == 's':
  35.             p = print('Generated password is: ')
  36.             strongPassword(p)
  37.             newPassword()
  38.         else:
  39.             choice = input("This is not correct answer! Please type 'w' or 's': ")
  40.  
  41. def newPassword():
  42.     '''Generate new password'''
  43.     choice = input('Do you want to generate new password? y/n: ')
  44.     while True:
  45.         if choice == 'y':
  46.             strongOrWeak()
  47.         if choice == 'n':
  48.             quit()
  49.         else:
  50.             choice = input("This is not correct answer! Please type 'y' or 'n': ")
  51.  
  52. strongOrWeak()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement