Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Password generator
- import random
- lower = True
- upper = False
- num = True
- special = False
- space = False
- print("Take note of syntax. Uppercase letter denotes default value used if input is invalid/blank. \nHitting ENTER repeatedly yields one (1) password with eight (8) lowercase alphanumeric characters.", end="\n\n")
- # Obtain parameters from user
- print("Will your password contain...", end="\n\n")
- if str(input("lowercase letters? (Y/n): ")).lower() == 'n':
- lower = False
- if str(input("UPPERCASE LETTERS? (y/N): ")).lower() == 'y':
- upper = True
- if str(input("NUM83R5? (Y/n): ")).lower() == 'n':
- num = False
- if str(input("$PEC!@|_ C|-|@R@CTER$? (y/N): ")).lower() == 'y':
- special = True
- if str(input("S p a c e s ? (y/N): ")).lower() == 'y':
- space = True
- length = input("How long will this password be? (Default=8) ")
- try:
- length = int(length)
- except ValueError:
- length = 8
- times = input("How many passwords do you want? (Default=1) ")
- try:
- times = int(times)
- except ValueError:
- times = 1
- # Create sample space
- alpha_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
- alpha_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
- numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
- special_char = ['.', ',', ';', ':',"'",'"', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '[', ']', '{', '}', '<', '>', '/', '=', '\\', '?', '+', '|', '`', '~']
- space_char = [' ']
- sample_space = []
- if lower:
- sample_space = sample_space + alpha_lower
- if upper:
- sample_space = sample_space + alpha_upper
- if num:
- sample_space = sample_space + numbers
- if special:
- sample_space = sample_space + special_char
- if space:
- sample_space = sample_space + space_char
- sample = ''.join(sample_space)
- # Generate password
- if times > 1:
- print("Here are your passwords:", end="\n")
- else:
- print("Here is your password:", end="\n")
- while times > 0:
- password = []
- size = length
- while size > 0:
- password.append(random.choice(sample))
- size -= 1
- print(''.join(password), end='\n')
- times -= 1
Add Comment
Please, Sign In to add comment