【发布时间】:2018-05-20 11:01:54
【问题描述】:
我正在尝试使用 bcrypt 检查保存在我的数据库中的哈希密码,但 json 响应当前返回如下:
[
{
"password": "$2a$10$8/o1McdQ24pL5MU7dkbhmewkjne83M2duPKp0cb6uowWvOPS"
}
]
这会导致 bcrypt 比较出错,因为它正在比较整个响应,而不仅仅是其中的哈希值。我怎样才能在我的响应中获得哈希值?以下是我的代码:
app.get('/checkHash/:username/:pass', function(req, res) {
console.log('below is the data');
console.log(req.params);
var pass = req.params.pass
var createPromise = interact.getHash(req.params.username);
//did promise
createPromise.then(function(createResponse) {
//below checks to see if the password value matches the hash
if(bcrypt.compareSync(pass, createResponse)) {
//this means that the hashes are the same for user login
res.json("yes");
} else {
//this means that the password hashes didn't match
res.json("no");
}
}).catch(function(err) {
console.log(err);
});
});
【问题讨论】: