bcrypt

Node.js bcrypt

函式资料

变数 说明
bcrypt.genSalt() 产生加盐资料
bcrypt.hash() 加密字串
bcrypt.compare() 比较加密字串

加密字串

const bcrypt = require('bcrypt');
const saltRounds = 10;
const myPlaintextPassword = 's0/\/\P4$$w0rD';
const someOtherPlaintextPassword = 'not_bacon';

bcrypt.genSalt(saltRounds, function(err, salt) {
    bcrypt.hash(myPlaintextPassword, salt, function(err, hash) {
        // Store hash in your password DB.
    });
});

比较加密字串

bcrypt.compare(myPlaintextPassword, hash, function(err, result) {
    // result == true
});

参考资料