-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakepasswd
executable file
·33 lines (26 loc) · 1.28 KB
/
makepasswd
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
#!/usr/bin/env python3
import argparse
import random
import string
BASE_CHOICES = frozenset(set(string.ascii_letters + string.digits + string.punctuation) - set('''lIoO1"'&$.,:='''))
def main(length, choices):
return ''.join(random.choice(choices) for _ in range(length))
if __name__ == '__main__':
# Parse the cmdline.
parser = argparse.ArgumentParser(description='Password generator.')
parser.add_argument('-D', '--exclude-digits', dest='digits', action='store_false', help='Exclude digit characters.')
parser.add_argument('-P', '--exclude-punct', dest='punctuation', action='store_false', help='Exclude punctuation characters.')
parser.add_argument('-E', '--exclude', type=str, help='Explicitly specify the charcters to exclude.')
parser.add_argument('-l', '--length', type=int, default=64, help='The length of the password to generate.')
parser.set_defaults(digits=True, punctuation=True)
args = parser.parse_args()
# Construct the set of characters to chose from.
choices = set(BASE_CHOICES)
if not args.digits:
choices -= set(string.digits)
if not args.punctuation:
choices -= set(string.punctuation)
if args.exclude:
choices -= set(args.exclude)
password = main(args.length, tuple(choices))
print(password)