-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (50 loc) · 1.93 KB
/
main.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
import random
from termcolor import colored
from ascii_module.choice_ascii_string import get_random_symbols, get_random_numbers, get_random_lower_case, \
get_random_upper_case
from settings_password_module.settings_password import print_password_generator_text, clear_screen, \
settings
from settings_password_module.ask_settings_from_user import get_settings_from_user, ask_if_change_settings
def generate_random_char(choices):
choice = random.choice(choices)
if choice == "lower":
return get_random_lower_case()
if choice == "upper":
return get_random_upper_case()
if choice == "numbers":
return get_random_numbers()
if choice == "symbols":
return get_random_symbols()
if choice == "spaces":
return " "
def password_generator():
finally_password = ''
password_length = settings["length"]
choices = list(filter(lambda status: settings[status] is True,
['lower', 'upper', 'symbols', 'numbers', 'spaces']))
for i in range(password_length):
finally_password += generate_random_char(choices)
return finally_password
def ask_user_to_generate_another_password():
while True:
user_answer = input(
'Regenerate? (y: yes, n: no, enter: yes): ').lower()
if user_answer in ['y', 'n', '']:
if user_answer == 'n':
return False
return True
else:
print(colored("Invalid input.", 'red'))
print(colored("Please try again.", 'red'))
def password_generator_loop():
while True:
print('-' * 30)
print(f'Your password generated: {password_generator()}')
if not ask_user_to_generate_another_password():
break
if __name__ == "__main__":
clear_screen()
print_password_generator_text()
ask_if_change_settings(settings)
password_generator_loop()
print(colored("Thank you choosing us.", 'green'))