-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_gen2.py
More file actions
76 lines (64 loc) · 2.1 KB
/
password_gen2.py
File metadata and controls
76 lines (64 loc) · 2.1 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
import sys
import random
import string
def generate_password(complexity,length):
while True:
if complexity == '1': # weak
characters = string.ascii_letters
elif complexity == '2': # medium
characters = string.ascii_letters + string.digits
elif complexity == '3': # strong
characters = string.ascii_letters + string.digits + string.punctuation
elif complexity == '4':
print('\nThank you and have a great day!\n')
sys.exit()
else:
print('\nError: Invalid Choice.')
break
password = ''.join(random.choice(characters) for _ in range(length))
return password
def user_input():
while True:
try:
length = int(input("\nEnter password length (min. 8 max. 64): "))
break
except ValueError:
print('\nError: Password length must be a number.\n')
return
if length <= 7 or length >= 65:
print('\nError: Invalid range.\n')
return
print("Select complexity level:")
print("[1] Weak")
print("[2] Medium")
print("[3] Strong")
print("[4] Quit")
choice_complexity = input('Your choice: ')
if choice_complexity not in ("1","2","3","4"):
pass
password = generate_password(length=length, complexity=choice_complexity)
if password is None:
print('')
else:
print('\nYour password is:',(password))
print()
def main():
os.system('cls' if os.name == 'nt' else 'clear')
app_name = 'Password generator v2'
print(f'{"-" * 48}')
print(f'{" " * 12}{app_name}{" " * 12}')
print(f'{"-" * 48}')
user_input()
while True:
response = input('Do you want to continue? (Y/N) ')
if response == 'y' or response == 'Y':
main()
elif response == 'n' or response == 'N':
print('\nThank you and have a great day!\n')
sys.exit()
else:
print('\nError: Please select Y or N.\n')
continue
if __name__ == '__main__':
main()