Пример #1
0
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
Пример #2
0
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
Пример #3
0
def generate_token(text, salt=api_key):
    hextime = hex(unixtime())[2:]
    sha = hashlib.sha256()
    sha.update(text + salt + hextime)
    return sha.hexdigest()[:32] + hextime
Пример #4
0
def generate_token(text, salt=api_key):
    hextime = hex(unixtime())[2:]
    sha = hashlib.sha256()
    sha.update(text + salt + hextime)
    return sha.hexdigest()[:32] + hextime