-
Notifications
You must be signed in to change notification settings - Fork 0
/
password_generator.py
64 lines (52 loc) · 2.19 KB
/
password_generator.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 string
import random
import argparse
import sys
def password_generator(length=20, lowercase=True, uppercase=True, numbers=True, symbols=True, punctuation=False):
"""Strong Password Generator.
Parameters
----------
length : int, optional
Password length. Default is 20.
lowercase : bool, optional
Include lowercase characters (abcdefghijklmnopqrstuvwxyz).
Default is True.
uppercase : bool, optional
Include uppercase characters (ABCDEFGHIJKLMNOPQRSTUVWXYZ).
Default is True.
numbers : bool, optional
Include numbers (0123456789).
Default is True.
symbols : bool, optional
Include common symbols (@#$%_-).
Default is True.
punctuation : bool, optional
Include all punctuation (!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~).
Default is False.
"""
if not any([lowercase, uppercase, numbers, symbols, punctuation]):
sys.tracebacklimit = 0
raise ValueError('Cannot set all characters to False!')
string_symbols = '@#$_-' * 5
chars = string.ascii_lowercase * lowercase
chars += string.ascii_uppercase * uppercase
chars += string.digits * numbers * 3
chars += string_symbols * symbols
chars += string.punctuation * punctuation
print(''.join(random.choice(chars) for _ in range(length)))
parser = argparse.ArgumentParser(description='Strong Password Generator.')
parser.add_argument('--length', '-l', type=int,
default=20, help='Set password length. Default is 20.')
parser.add_argument('--lowercase', '-lc', action='store_false',
help='Remove lowercase characters.')
parser.add_argument('--uppercase', '-uc', action='store_false',
help='Remove uppercase characters.')
parser.add_argument('--numbers', '-n', action='store_false',
help='Remove numbers.')
parser.add_argument('--symbols', '-s', action='store_false',
help='Remove common symbols (@#$_-).')
parser.add_argument('--punctuation', '-p', action='store_true',
help=f'Include all punctuation.')
kwargs = vars(parser.parse_args())
if __name__ == '__main__':
password_generator(**kwargs)