paulo@78: import urlparse paulo@78: paulo@78: paulo@78: PIN_KEY = "llpin" paulo@78: PIN_FN = "_%s" % PIN_KEY paulo@78: paulo@78: paulo@78: class PinFailError(Exception): paulo@78: pass paulo@78: paulo@78: paulo@78: def load(): paulo@78: ret = None paulo@78: paulo@78: try: paulo@78: with open(PIN_FN) as pin_f: paulo@78: ret = pin_f.read().strip() paulo@78: except IOError: paulo@78: pass paulo@78: paulo@78: return ret paulo@78: paulo@78: paulo@78: def parse_cookies(environ): paulo@78: return urlparse.parse_qs(environ.get("HTTP_COOKIE", "")) paulo@78: paulo@78: paulo@78: def check(cookies): paulo@78: if PIN_KEY not in cookies: paulo@78: raise PinFailError() paulo@78: paulo@78: pin = cookies[PIN_KEY][0] paulo@78: if pin != load(): paulo@78: raise PinFailError() paulo@78: paulo@78: return pin