Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- import random, string
- '''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.
- Source: PracticePython.org - Exercise 16'''
- def weakPassword(x):
- '''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']
- password = random.choice(passwordsList)
- print(password)
- def averagePassword(x):
- '''Pick 1 word from each list and combine them with random number'''
- adjectivesList = ['Super', 'Fancy', 'Crazy', 'Bald', 'Sneaky', 'Shiny', 'Stupid', 'Beautiful', 'Strong', 'Young', 'Dank']
- animalsList = ['Cat', 'Dog', 'Horse', 'Dragon', 'Python', 'Lizard', 'Cow', 'Bull', 'Bee', 'Snake', 'Spider', 'Rabbit']
- randomList = ['Trump', 'JackDaniels', 'Weed', 'Alcoholic', 'Minecraft', 'Obama', 'Xiaomi', 'Janusz', 'Wine', 'Pizza']
- a = random.choice(adjectivesList)
- b = random.choice(animalsList)
- c = random.choice(randomList)
- password = a + b + c + str(randint(1, 100))
- print(password)
- def strongPassword(x):
- '''Generate random password'''
- password = []
- a = random.sample(string.ascii_letters, k = randint(3, 8)) #random letters
- a = ''.join(a)
- password.append(a)
- b = random.sample(string.digits, k = randint(3, 8)) #random digits
- b = ''.join(b)
- password.append(b)
- c = random.sample(string.punctuation, k = randint(3, 8)) #random symbols
- c = ''.join(c)
- password.append(c)
- random.shuffle(password) #shuffle digits, symbols and letters order
- password = ''.join(password)
- print(password)
- def chooseStrong():
- '''Choose how strong password will be'''
- choice = input('Do you want weak, average or strong password? w/a/s: ')
- while True:
- if choice == 'w':
- p = print('Generated password is: ')
- weakPassword(p)
- newPassword()
- if choice == 'a':
- p = print('Generated password is: ')
- averagePassword(p)
- newPassword()
- if choice == 's':
- p = print('Generated password is: ')
- strongPassword(p)
- newPassword()
- else:
- choice = input("This is not correct answer! Please type 'w', 'a' or 's': ")
- def newPassword():
- '''Generate new password'''
- choice = input('Do you want to generate new password? y/n: ')
- while True:
- if choice == 'y':
- chooseStrong()
- if choice == 'n':
- quit()
- else:
- choice = input("This is not correct answer! Please type 'y' or 'n': ")
- chooseStrong()
Add Comment
Please, Sign In to add comment