#!/usr/bin/python import sys, hmac, hashlib, getopt def usage(out): out.write("usage: vhtpasswd [-h] FILE\n") opts, args = getopt.getopt(sys.argv[1:], "h") for o, a in opts: if o == "-h": usage(sys.stdout) sys.exit(0) if len(args) < 1: usage(sys.stderr) sys.exit(1) def hashpw(usr, pw): dig = hmac.new(pw, digestmod=hashlib.sha1) dig.update(usr) return dig.hexdigest() def findpw(fn, name): with open(fn) as fp: for line in fp: usr, pw = line.strip().split(':') if usr == name: return pw return None usr = sys.stdin.readline().strip() gpw = sys.stdin.readline().strip() if findpw(args[0], usr) == hashpw(usr, gpw): sys.exit(0) sys.exit(1)