Created
August 17, 2019 03:42
-
-
Save tjunxiang92/74fe4ee4c1a3ce8065889e4f75b6b646 to your computer and use it in GitHub Desktop.
Telegram Web Login JS Check Hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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