Skip to content

Instantly share code, notes, and snippets.

@MahouSirin
Last active November 25, 2021 04:23
Show Gist options
  • Save MahouSirin/8fd0390ba5c77cd52a0d3cd986ff43ab to your computer and use it in GitHub Desktop.
Save MahouSirin/8fd0390ba5c77cd52a0d3cd986ff43ab to your computer and use it in GitHub Desktop.
const crypto = require('crypto');
module.exports = () => {
const time = Math.floor(Date.now() / 1000);
const DS_SALT = '6cqshh5dhw73bzxn20oexa9k516chk7s';
const randomChar = randomString(6);
const data = `salt=${DS_SALT}&t=${time}&r=${randomChar}`;
const hash = crypto.createHash('md5').update(data).digest('hex');
return `${time},${randomChar},${hash}`;
}
funcion randomString(len = 6, an) => {
an = an && an.toLowerCase();
let str = '';
let i = 0;
let min = an === 'a' ? 10 : 0;
let max = an === 'n' ? 10 : 62;
for (;i++ < len;) {
let r = Math.random() * (max - min) + min << 0;
str += String.fromCharCode(r += r > 9 ? r < 36 ? 55 : 61 : 48);
}
return str;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment