doc: Fixed typo.
[ashd.git] / etc / extauth / vhtpasswd
CommitLineData
ea4e6725
FT
1#!/usr/bin/python
2
3import sys, hmac, hashlib, getopt
4
5def usage(out):
6 out.write("usage: vhtpasswd [-h] FILE\n")
7
8opts, args = getopt.getopt(sys.argv[1:], "h")
9for o, a in opts:
10 if o == "-h":
11 usage(sys.stdout)
12 sys.exit(0)
13if len(args) < 1:
14 usage(sys.stderr)
15 sys.exit(1)
16
17def hashpw(usr, pw):
18 dig = hmac.new(pw, digestmod=hashlib.sha1)
19 dig.update(usr)
20 return dig.hexdigest()
21
22def findpw(fn, name):
23 with open(fn) as fp:
24 for line in fp:
25 usr, pw = line.strip().split(':')
26 if usr == name:
27 return pw
28 return None
29
30usr = sys.stdin.readline().strip()
31gpw = sys.stdin.readline().strip()
32if findpw(args[0], usr) == hashpw(usr, gpw):
33 sys.exit(0)
34sys.exit(1)