I am creating an account signup system for a React app. I am having an issue when trying to hash a password using Bcrypt. My function I use to hash a password is here:
async function genPassword(password) {
let hashpass = bcrypt.hash(String(password), 9)
return hashpass
}
I call this code later during an SQL call here:
const sql = "INSERT INTO USER (userFName, UserLName, userPhone, IsDelete, userEmail, userPassword) VALUES (?, ?, ?, ?, ?, ?);"
db.query(sql, [fname, lname, phone, 0, email, String(genPassword(password))], (err, data, fields, ) => {
//Code to follow omitted
I got this to upload to my database, but got this value in mySQL workbench for the password: Screenshot
As you can see, I get an [Object Promise] instead of the hash. Similarly, I get Promise { <pending> }
when I console.log this.
Can anyone see what I may have done incorrectly here? When I hash this in a separate file using bcrypt this works fine, so I am quite confused as to where I have made a mistake.