Skip to content

Instantly share code, notes, and snippets.

@xen xen/
Last active Jan 18, 2020

What would you like to do?
telegram site auth
# implementation of Telegram site authorization checking algorithm
# for more information
import collections
import hmac
import hashlib
def check_string(d, token):
secret = hashlib.sha256()
sorted_params = collections.OrderedDict(sorted(d.items()))
param_hash = sorted_params.pop('hash')
msg = "\n".join(["{}={}".format(k, v) for k, v in sorted_params.items()])
if param_hash ==, msg.encode('utf-8'), digestmod=hashlib.sha256).hexdigest():
return True
return False

This comment has been minimized.

Copy link

abramsymons commented Jan 18, 2020


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.