Hopefully the password hash you're storing has been salted with a random salt per record. That salt should either be stored in a separate column, or combined into the stored password hash somehow.
If you hash the same password again, but use a different salt, then you will get a different result.
The documentation suggests that you need to use the
bcrypt.compare
function to compare the plaintext password to the stored hash:
bcrypt.compare(myPlaintextPassword, hash, function(err, result) {
});
Also, why are you calling the
Sync
methods in an
async
function?
async function passCheck(event){
var fromDB = await pool.query('SELECT password FROM user WHERE email = ?', event.emailID);
var passwordMatch = await bcrypt.compare(event.password, fromDB);
if (passwordMatch) {
console.log("valid");
}
else {
console.log("invalid");
}
}