Skip to content

Instantly share code, notes, and snippets.

@JrooTJunior
Forked from xen/check_hash.py
Last active February 14, 2024 07:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save JrooTJunior/887791de7273c9df5277d2b1ecadc839 to your computer and use it in GitHub Desktop.
Save JrooTJunior/887791de7273c9df5277d2b1ecadc839 to your computer and use it in GitHub Desktop.
telegram site auth
# implementation of Telegram site authorization checking algorithm
# for more information https://core.telegram.org/widgets/login#checking-authorization
import collections
import hmac
import hashlib
def check_string(data, token):
secret = hashlib.sha256()
secret.update(token.encode('utf-8'))
sorted_params = collections.OrderedDict(sorted(d.items()))
param_hash = data.get('hash', '')
msg = "\n".join(["{}={}".format(k, v) for k, v in sorted_params.items() if k != 'hash'])
return param_hash == hmac.new(secret.digest(), msg.encode('utf-8'), digestmod=hashlib.sha256).hexdigest():
@Forevka
Copy link

Forevka commented Jul 4, 2019

спасибо, думал самому писать

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment