-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_password2.py
More file actions
51 lines (37 loc) · 1.4 KB
/
Copy pathcreate_password2.py
File metadata and controls
51 lines (37 loc) · 1.4 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
import string
import argparse
import random
def create_password(length , upper = False, lower = False, digits = False, pun = False):
"""
Args:
length(int)
upper (bool)
lower (bool)
digits (bool)
pun (bool)
Raises:
TypeError
Returns:
password
"""
pool = ''
if upper:
pool += string.ascii_uppercase
if lower:
pool += string.ascii_lowercase
if digits:
pool += string.digits
if pun:
pool = string.punctuation
if pool == '':
pool = string.ascii_letters
return (''.join(random.choices(pool, k=length)))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="password creator")
parser.add_argument('length', type=int, help="Length of password")
parser.add_argument('-u', '--upper', help="Use upper case in password", action="store_true")
parser.add_argument('-l', '--lower', help="Use lower case in password", action="store_true")
parser.add_argument('-d', '--digits', help="Use digits in password", action="store_true")
parser.add_argument('-p', '--pun', help="Use punctuation in password", action="store_true")
args = parser.parse_args()
print(create_password(args.length, args.upper, args.lower, args.digits, args.pun))