Reputation: 45
I really don't know about this problem about bcrypt.compare function when someone join my website, creating password with 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,
});
and in login I just compare with using 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);
}
}));
};
when I excute code just return incorrect-password why bcrypt.compare return false? Please help me
Upvotes: 0
Views: 140
Reputation: 45
I found the solution. because In database password column size is too small for hashing I extend password column in database it works
Upvotes: 1