-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordGenerator.py
More file actions
56 lines (45 loc) · 1.71 KB
/
Copy pathPasswordGenerator.py
File metadata and controls
56 lines (45 loc) · 1.71 KB
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
import random
import string
tryAgain = True
while tryAgain:
print("Welcome to the password generator.\n")
# Pwd length and strength
try:
length = int(input("How long would you like your password to be?\n"))
except Exception:
print("Invalid input type. Restarting.")
continue
if length < 0:
print("Cannot have negative length. Restarting.")
continue
passwordStrength = input("How strong would you like your password to be? Weak, medium or strong\n")
# Symbols to go in password
numberList = [str(i) for i in range(1,10)]
letterListLowerCase = list(string.ascii_lowercase)
letterListUpperCase = list(string.ascii_uppercase)
symbolsList = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '\'', '\"']
# Match password strength
if passwordStrength.upper() == "STRONG":
totalList = numberList.copy()
totalList.extend(letterListUpperCase)
totalList.extend(letterListLowerCase)
totalList.extend(symbolsList)
elif passwordStrength.upper() == "MEDIUM":
totalList = numberList.copy()
totalList.extend(letterListUpperCase)
totalList.extend(letterListLowerCase)
elif passwordStrength.upper() == "WEAK":
totalList = numberList.copy()
totalList.extend(letterListLowerCase)
else:
print("Choose out of weak, medium and strong.")
continue
# Convert to a string password
print(totalList)
passList = random.sample(totalList, length)
print(passList)
password = ''.join(passList)
print("You password is {}".format(password))
if (input("Would you like to go again (yes/no)?")).casefold() != "yes":
tryAgain = False
print("Bye now!")