-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassgen.py
More file actions
executable file
·61 lines (53 loc) · 1.95 KB
/
passgen.py
File metadata and controls
executable file
·61 lines (53 loc) · 1.95 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
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# -*- coding: utf8 -*-
from __future__ import print_function
import argparse
import random
import string
import sys
def get_parser():
parser = argparse.ArgumentParser(
description="This is a sample of argparse.",
epilog="This is an additional description appears in help footer.",
)
parser.add_argument('-l',
'--length',
action='store',
type=int,
default=12,
help='length of password.')
parser.add_argument('-A',
'--with-out-ascii',
action='store_true',
default=False,
help='without ascii letters.')
parser.add_argument('-P',
'--with-out-punctuation',
action='store_true', default=False,
help='without punctuations.')
parser.add_argument('-U',
'--with-out-uppercase',
action='store_true',
default=False,
help='without upper case letters.')
return parser.parse_args()
def generate(length, with_out_ascii=False, with_out_uppercase=False, with_out_punctuation=False):
seed = string.digits
if not with_out_ascii:
seed = seed + string.ascii_lowercase
if not with_out_uppercase and not with_out_ascii:
seed = seed + string.ascii_uppercase
if not with_out_punctuation and not with_out_ascii:
seed = seed + string.punctuation
return ''.join(random.choice(seed) for _ in range(length))
def main():
args = get_parser()
password = generate(args.length,
args.with_out_ascii,
args.with_out_uppercase,
args.with_out_punctuation)
sys.stdout.write(password)
print()
if __name__ == '__main__':
main()
# vim: et sw=4 ts=4