def is_valid_token(text, token, salt=api_key): if not (text and token): return False hextime = token[-8:] sha = hashlib.sha256() sha.update(text + salt + hextime) if sha.hexdigest()[:32] + hextime == token: timedelta = unixtime() - int(hextime, 16) if 0 < timedelta < 3600: return True return False
def generate_token(text, salt=api_key): hextime = hex(unixtime())[2:] sha = hashlib.sha256() sha.update(text + salt + hextime) return sha.hexdigest()[:32] + hextime