-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassgen.py
More file actions
executable file
·29 lines (26 loc) · 1.17 KB
/
Copy pathpassgen.py
File metadata and controls
executable file
·29 lines (26 loc) · 1.17 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
#!/usr/bin/python3
from argparse import ArgumentParser
from secrets import SystemRandom
from string import ascii_lowercase, ascii_uppercase, digits, punctuation
if __name__ == "__main__":
parser = ArgumentParser(description = "Generate random password.")
parser.add_argument("-n",action = 'store_true', help = "Have numberss in the passwrod")
parser.add_argument("-a",action = 'store_true', help = "Have lowercase characters in the passwrod")
parser.add_argument("-A",action = 'store_true', help = "Have uppercase characters in the passwrod")
parser.add_argument("-s",action = 'store_true', help = "Have symbols in the passwrod")
parser.add_argument("-l", type = int, metavar= "length", help = "The length of password", default = 16)
command = parser.parse_args()
r = SystemRandom()
password = []
valid_chars = ''
if command.n:
valid_chars += digits
if command.a:
valid_chars += ascii_lowercase
if command.A:
valid_chars += ascii_uppercase
if command.s:
valid_chars += punctuation
if not valid_chars:
valid_chars = digits
print("".join([r.choice(valid_chars) for i in range(command.l)]))