-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpasswordGenerator.py
90 lines (71 loc) · 2.16 KB
/
passwordGenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import random
import secrets
import string as str
class passwordGenerator:
@staticmethod
def genSequence(conditions):
possibleCharacters = [
str.ascii_lowercase,
str.ascii_uppercase,
str.digits,
str.punctuation,
]
sequence = ""
for x in range(len(conditions)):
if conditions[x]:
sequence += possibleCharacters[x]
else:
pass
return sequence
@staticmethod
def generatePassword(sequence, passlength=8):
password = "".join((secrets.choice(sequence) for i in range(passlength)))
return password
class interface:
hasCharacters = {
"lowercase": True,
"uppercase": True,
"digits": True,
"punctuation": True,
}
@classmethod
def changeHasCharacter(cls, change):
try:
cls.hasCharacters[change]
except:
print("invalid")
else:
cls.hasCharacters[change] = not cls.hasCharacters[change]
print(f"{change} is now set to {cls.hasCharacters[change]}")
@classmethod
def showCharacters(cls):
print(cls.hasCharacters)
def generatingPassword(self, lenght):
sequence = passwordGenerator.genSequence(list(self.hasCharacters.values()))
print(passwordGenerator.generatePassword(sequence, lenght))
def listToVerticalString(list):
toReturn = ""
for member in list:
toReturn += f"{member} \n"
return toReturn
class running:
def decideOperation():
userInput = input("pass: ")
try:
int(userInput)
except:
interface.changeHasCharacter(userInput)
else:
interface().generatePassword(int(userInput))
finally:
print("\n\n")
def run(self):
menu = f"""Welcome to the PassGen App!
Commands:
<generate password ->
<lenght of the password>
commands to change the characters to be used to generate passwords:{listToVerticalString(interface.has_characters.keys())}"""
print(menu)
while True:
decideOperation()
running().run()