bcrypt
Node.js bcrypt
Categories:
函式資料
變數 | 說明 |
---|---|
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
});