📜  bcrypt nodejs 哈希密码 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:45.251000             🧑  作者: Mango

代码示例2
var bcrypt = dcodeIO.bcrypt; 

    /** One way, can't decrypt but can compare */
    var salt = bcrypt.genSaltSync(10);

    /** Encrypt password */
    bcrypt.hash('anypassword', salt, (err, res) => {
        console.log('hash', res)
        hash = res
        compare(hash)
    });

    /** Compare stored password with new encrypted password */
    function compare(encrypted) {
        bcrypt.compare('aboveusedpassword', encrypted, (err, res) => {
            // res == true or res == false
            console.log('Compared result', res, hash) 
        })
    }

// If u want do the same with NodeJS use this:
/*        var bcrypt = require('bcryptjs')    */