![](/img/trans.png)
[英]Why isn't salt required to compare whether password is correct in bcrypt?
[英]I don't know why bcrypt.compare with hashed password isn't same
當有人加入我的網站時,我真的不知道關於 bcrypt.compare function 的這個問題,使用 hash 創建密碼
const hash = await bcrypt.hash(u_password, 12);
const user = await User.create({
u_email,
u_password: hash,
u_name,
u_birth,
u_nation,
u_phnbr,
u_sex,
});
在登錄時,我只是與使用 bcrypt.compare 進行比較
module.exports = (passport) => {
passport.use(new LocalStrategy({
usernameField: 'u_email',
passwordField: 'u_password',
}, async (u_email, u_password, done) => {
try {
const exUser = await User.findOne({ where: { u_email } });
if (exUser) {
const result = await bcrypt.compare(u_password, exUser.u_password);
console.log(u_password);
console.log(exUser.u_password);
if (result) {
done(null, exUser);
} else {
done(null, false, { message: 'incorrect password.' });
}
} else {
done(null, false, { message: 'non-exist user'});
}
} catch (error) {
console.log(error);
done(error);
}
}));
};
當我執行代碼時只返回不正確的密碼,為什么 bcrypt.compare 返回 false? 請幫我
我找到了解決方案。 因為在數據庫中密碼列的大小對於散列來說太小了我在數據庫中擴展密碼列它可以工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.