-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
59 lines (50 loc) · 2.77 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
import argparse
import pyperclip
from modules.password_generator import PasswordGenerator
from modules.history_manager import HistoryManager
def parse_arguments():
parser = argparse.ArgumentParser(description='Password Generator CLI')
parser.add_argument('-l', '--length', type=int, default=8, help='Length of the password')
parser.add_argument('--no-digits', action='store_false', help='Do not include digits in the password')
parser.add_argument('--no-special', action='store_false', help='Do not include special characters in the password')
parser.add_argument('-c', '--complexity', choices=['low', 'medium', 'high'], default='medium', help='Complexity level of the password')
parser.add_argument('--avoid-similar', action='store_true', help='Avoid similar looking characters')
parser.add_argument('--pronounceable', action='store_true', help='Generate a pronounceable password')
parser.add_argument('-k', '--keyword', type=str, help='Provide a keyword to generate a modified version of the password')
parser.add_argument('--view-history', action='store_true', help='View the password generation history')
parser.add_argument('--clear-history', action='store_true', help='Clear the password generation history')
parser.add_argument('--validity', type=int, default=60, help='Number of days before the password expires')
parser.add_argument('--include-chars', type=str, help='Include these specific characters in the password')
parser.add_argument('--exclude-chars', type=str, help='Exclude these specific characters from the password')
return parser.parse_args()
def main():
args = parse_arguments()
history_manager = HistoryManager()
if args.view_history:
history_manager.view_history()
return
elif args.clear_history:
history_manager.clear_history()
return
generator = PasswordGenerator(length=args.length,
use_digits=args.no_digits,
use_special_chars=args.no_special,
level=args.complexity,
avoid_similar=args.avoid_similar,
include_chars=args.include_chars,
exclude_chars=args.exclude_chars)
password = ""
if args.keyword:
password = generator.keyword_based(args.keyword)
elif args.pronounceable:
password = generator.generate_pronounceable()
else:
password = generator.generate()
history_manager.save_to_history(password, args.validity)
strength = generator.assess_strength(password)
print(f'Generated Password: {password}')
print(f'Strength: {strength}')
pyperclip.copy(password)
print('Password copied to clipboard!')
if __name__ == '__main__':
main()