[英]bcrypt.compareSync doesn't work on sequelize
Can someone help me figure out why bcrypt.compareSync
function doesn't work on my case : 有人可以帮我弄清楚为什么
bcrypt.compareSync
函数对我的情况不起作用:
models/patient.js 车型/ patient.js
const bcrypt = require('bcryptjs');
module.exports = (sequelize, Sequelize) => {
const Patient = sequelize.define('Patient', {
email: {
type: Sequelize.STRING,
allowNull: false,
},
password: {
type: Sequelize.STRING,
allowNull: false,
},
}, {
classMethods: {
associate: (models) => {
// associations can be defined here
}
},
instanceMethods: {
//
verifyPassword: function(password,hash) {
bcrypt.compareSync(password,hash);
}
}
});
return Patient;
};
controllers/patients.js EDITED 控制器/ Patients.js编辑
retrieve(req, res) {
return Patient
.find({
where: {
email: req.body.email,
}
})
.then(patient => {
const result = Patient.build().verifyPassword(req.body.password, patient.password);
if (!result) {
console.log('wrong password')
} else return res.status(201).send(patient);
})
}
My request supposed to return the patient that correspond to the email and password that is typed on the request but it return this : 我的请求应该返回与在请求中键入的电子邮件和密码相对应的患者,但它返回以下内容:
EDIT : Error issue resolved but still getting false result (it returns the 'wrong password' string) even when I make a request with the right password. 编辑 :错误问题已解决,但即使我使用正确的密码提出请求,仍然会得到错误的结果(它返回“错误的密码”字符串)。
You forgot to return anything from verifyPassword
. 您忘记从
verifyPassword
返回任何verifyPassword
。
verifyPassword: function(password,hash) {
return bcrypt.compareSync(password,hash);
}
Now it will return true
if password is correct, otherwise false
. 现在,如果密码正确,它将返回
true
,否则返回false
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.