3 import sys, os, termios, hmac, hashlib, getopt, getpass
6 out.write("usage: mkhtpasswd [-h] FILE USERNAME\n")
8 opts, args = getopt.getopt(sys.argv[1:], "h")
18 dig = hmac.new(pw, digestmod=hashlib.sha1)
20 return dig.hexdigest()
23 sys.stderr.write("mkhtpasswd: username cannot contain `:'\n")
27 if os.path.exists(args[0]):
28 with open(args[0]) as fp:
30 usr, pw = line.strip().split(':')
33 passwds[args[1]] = hashpw(args[1], getpass.getpass())
35 with open(args[0], "w") as fp:
36 for usr, pw in passwds.iteritems():
37 fp.write("%s:%s\n" % (usr, pw))