-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_gen.py
More file actions
70 lines (57 loc) · 1.94 KB
/
password_gen.py
File metadata and controls
70 lines (57 loc) · 1.94 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
import os
import sys
import random
import string
def generate_password(length, include_digits=True, include_symbols=True):
characters = string.ascii_letters # all letters
if include_digits:
characters += string.digits # add digits
if include_symbols:
characters += string.punctuation # add symbols
# Generate the password
password = ''.join(random.choice(characters) for _ in range(length))
return password
def user_input():
#password length
while True:
try:
length = int(input("Enter the desired length of your password: "))
break
except ValueError:
print('Input must be a number.\n')
#include digits
while True:
include_digits = input("Include digits? [y/n]: ")
if include_digits == 'y' or include_digits == 'n':
break
else:
print('Invalid input. Please enter y or n.')
#include symbols
while True:
include_symbols = input("Include symbols? [y/n]: ")
if include_symbols == 'y' or include_symbols == 'n':
break
else:
print('Invalid input. Please enter y or n.')
password = generate_password(length, include_digits=include_digits, include_symbols=include_symbols) # type: ignore
print("\nYour password is:", password)
print('\n')
def main():
os.system('cls' if os.name == 'nt' else 'clear')
app_name = 'Password Generator'
print(f'{"-" * 48}')
print(f'{" " * 12}{app_name}{" " * 12}')
print(f'{"-" * 48}')
user_input()
while True:
response = input('Generate another password? (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()