[英]bcrypt.compareSync doesn't work on sequelize
有人可以幫我弄清楚為什么bcrypt.compareSync
函數對我的情況不起作用:
車型/ 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;
};
控制器/ 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);
})
}
我的請求應該返回與在請求中鍵入的電子郵件和密碼相對應的患者,但它返回以下內容:
編輯 :錯誤問題已解決,但即使我使用正確的密碼提出請求,仍然會得到錯誤的結果(它返回“錯誤的密碼”字符串)。
您忘記從verifyPassword
返回任何verifyPassword
。
verifyPassword: function(password,hash) {
return bcrypt.compareSync(password,hash);
}
現在,如果密碼正確,它將返回true
,否則返回false
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.