美文网首页
给你的密码加盐

给你的密码加盐

作者: __越过山丘__ | 来源:发表于2019-01-03 16:58 被阅读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());
};

相关文章

网友评论

      本文标题:给你的密码加盐

      本文链接:https://www.haomeiwen.com/subject/uqhqrqtx.html