标签:
To hash a password:
var bcrypt = require(‘bcryptjs‘); var salt = bcrypt.genSaltSync(10); var hash = bcrypt.hashSync("B4c0/\/", salt); // Store hash in your password DB.
To check a password:
// Load hash from your password DB. bcrypt.compareSync("B4c0/\/", hash); // true bcrypt.compareSync("not_bacon", hash); // false
Auto-gen a salt and hash:
var hash = bcrypt.hashSync(‘bacon‘, 8);
To hash a password:
var bcrypt = require(‘bcryptjs‘); bcrypt.genSalt(10, function(err, salt) { bcrypt.hash("B4c0/\/", salt, function(err, hash) { // Store hash in your password DB. }); });
To check a password:
// Load hash from your password DB. bcrypt.compare("B4c0/\/", hash, function(err, res) { // res == true }); bcrypt.compare("not_bacon", hash, function(err, res) { // res = false });
Auto-gen a salt and hash:
bcrypt.hash(‘bacon‘, 8, function(err, hash) { });
标签:
原文地址:http://www.cnblogs.com/surahe/p/5249894.html