forked from fabiofumarola/docker-nginxify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_generator.py
executable file
·36 lines (26 loc) · 1008 Bytes
/
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
#!/usr/bin/env python
import crypt
import argparse
import os
import sys
parser = argparse.ArgumentParser(description="nginx auth file generator")
parser.add_argument('--file', dest='dest_folder', default='./nginx/htpasswd/',
help="the folder to save the new username:password pair")
parser.add_argument('--user', dest='user',
help="the username for the new user")
parser.add_argument('--pwd', dest='pwd',
help="the password for the new user")
args = parser.parse_args()
if args.user is None or args.pwd is None:
print('specify a value for --user an --pwd')
sys.exit(1)
if len(args.pwd) < 8:
print('the password should have length greater than 8')
sys.exit(1)
if not os.path.exists(args.dest_folder):
os.makedirs(args.dest_folder)
crypted_pwd = crypt.crypt(args.pwd, "$1$random_salt")
dest_file = args.dest_folder + "secure"
with open(dest_file, 'a') as f:
f.write("%s:%s\n" % (args.user, crypted_pwd))
print('successufly generate password for user ', args.user)