Skip to content

Instantly share code, notes, and snippets.

@tjunxiang92
Created August 17, 2019 03:42
Show Gist options
  • Save tjunxiang92/74fe4ee4c1a3ce8065889e4f75b6b646 to your computer and use it in GitHub Desktop.
Save tjunxiang92/74fe4ee4c1a3ce8065889e4f75b6b646 to your computer and use it in GitHub Desktop.
Telegram Web Login JS Check Hash
var CryptoJS = require("crypto-js");
var bot_token = "xxxxxxxxx:xxxxxxxxxxxxx";
// TODO: split the web response into the following fields
var hash = "xxx";
var data = {
"username": "xxxx",
"auth_date": "xxxx",
"first_name": "xxxxxx",
"id": "xxxxxxx",
"photo_url": "https://t.me/i/userpic/320/xxxxxxx.jpg",
}
var genHash = CryptoJS.HmacSHA256(
Object.keys(data).sort().map(k => `${k}=${data[k]}`).join("\n"),
CryptoJS.SHA256(bot_token)
);
var genHashStr = CryptoJS.enc.Hex.stringify(hash);
console.log('====================================');
console.log(genHashStr);
console.log(genHashStr == hash);
console.log('====================================');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment