def get_user(self, login, password): pwd = safe_bytes(password) login = safe_bytes(login) db = bsddb.hashopen(self.filename, 'r') key = b'%s\x00%s\x00userPassword' % (login, self.realm) try: if db[key] != pwd: raise KeyError obj = SasldbAuthObject(login) return defer.succeed(obj) except (KeyError,): pass return defer.fail(failure.Failure(EInvalidCredentials()))
def __init__(self, filename, realm): self.filename = filename self.realm = safe_bytes(realm)