def verify_token(self, token, token_type='pwreset'): """Verify a user-specific token.""" token = str(token) decoded = base64.urlsafe_b64decode(token) expires, mac = decoded.split(':') if float(expires) > time.time(): raise errors.ValidationError('Expired token.') expected = self.get_token(token_type=token_type, expires=int(expires)) if not utils.compare_digest(expected, token): raise errors.ValidationError('Invalid token.') return True
def check_signature(request): secret = os.environ.get('GITHUB_SECRET', '') signature = request.headers.get('X-Hub-Signature') if not signature: return False mac = hmac.new(secret, request.data, hashlib.sha1).hexdigest() return compare_digest("sha1=" + mac, str(signature))
def verify_answer(self, answer): return utils.compare_digest( pbkdf2.crypt(answer, self.answer_hash), self.answer_hash)