在这里,我的req.body.newTransactionPassword="1234";我想加密那个值,但是大小写是函数,最终执行。我想把它输入到我的order.Is中。
console.log("1");
var nwtp=req.body.newTransactionPassword;
var setPassword = function(nwtp,cb){
console.log("2");
bcrypt.genSalt( 10, function(err, salt) {
bcrypt.hash(nwtp, salt, function(err, hash) {
if (err) {
console.log(err);
return cb(err);
} else {
nwtp = hash;
console.log(nwtp);
return nwtp;
}
});
});
}
setPassword(nwtp);
console.log(nwtp);
console.log("3");
输出是
1
2
1234
3
$2a$10$kVmybMj7SsD5ip11lCU3AOFd4ZdKL6/0DzKADYcplIDx9qdZJAy/a
我能把它按那个顺序..?
1
2
$2a$10$kVmybMj7SsD5ip11lCU3AOFd4ZdKL6/0DzKADYcplIDx9qdZJAy/a
3
$2a$10$kVmybMj7SsD5ip11lCU3AOFd4ZdKL6/0DzKADYcplIDx9qdZJAy/a发布于 2015-11-02 11:55:53
您应该使用异步库https://github.com/caolan/async。
那么,您的代码可能如下所示
var saltResult = null;
var hashResult = null;
async.series([
function(next) {
bcrypt.genSalt( 10, function(err, salt) {
saltResult = salt;
next(err);
});
},
function(next) {
bcrypt.hash(nwtp, saltResult, function(err, hash) {
hashResult = hash;
next(err);
});
}],
function(err) {
// your final processing here
}
);https://stackoverflow.com/questions/33476735
复制相似问题