给你的密码加盐

2019-01-03  本文已影响0人  __越过山丘__
/*
 * 10位盐
 * 时间戳(2)+随机字母(8)
 */
const salt = () => {
    var time = Date.now() % 100,
        str = '';
    time = time === 0 ? '00' : String(time);
    for (let i = 0; i < 8; i++) {
        const base = Math.random() < 0.5 ? 65 : 97;
        str += String.fromCharCode(
            base + 
            Math.floor(
                Math.random() * 26 
            )
        );
    }
    return time + str;
};
const md5 = (text) => {
    return crypto.createHash("md5").update(String(text)).digest("hex");
};
const encrypt = (password) => {
    return md5(md5(password) + salt());
};
上一篇下一篇

猜你喜欢

热点阅读