I make use of the string library to get capital and lowercase letters, numbers, and symbols. There were symbols in there that I did not want to be in the passwords (the ones in 'unwanted_characters') so I made a function to extract only the characters I wanted.
import random, string
password = []
unwanted_characters = ['"', '+', '~', '`', "'", '=', '<', '>', '{', '}', ';', ':', '[', ']', '.',
',', '^', ')', '(']
wanted_characters = []
class random_pass:
def __init__(self, no_of_characters):
self.wanted_characters = wanted_characters
self.no_of_characters = no_of_characters
def desired_characters(self):
for char in string.printable:
if char not in unwanted_characters:
self.wanted_characters.append(char)
return self.wanted_characters
def random_everything(self):
for letter in range(self.no_of_characters + 1):
result = random.choice(self.wanted_characters)
password.append(result)
return password
def get_result(self):
for readable_password in password:
print(readable_password, end='')
max_characters = int(input("Enter the lenght of your password: "))
random_password = random_pass(max_characters)
random_password.desired_characters()
random_password.random_everything()
random_password.get_result()
Aucun commentaire:
Enregistrer un commentaire