I have node.js code mentioned below:
router.post("/addData", async (req, res)=>{
const password = req.body.password;
console.log("before.password: ", password);
await bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(password, salt, (err, hash) => {
if (err) {
console.log("bcrypt error: ", err);
}
console.log("hash passw: ", hash);
password = hash;
});
});
console.log("after.password: ", password);
});
Actual output is:
before.password: passw
after.password: passw
hash passw: $2a$10$TWiXiJQK2abV1T2fvH.nIuqCYKNrMDYaz2PHpATswIVDPYsMw/QsG
I need output which is expected output as shown below:
before.password: passw
hash passw: $2a$10$TWiXiJQK2abV1T2fvH.nIuqCYKNrMDYaz2PHpATswIVDPYsMw/QsG
after.password: $2a$10$TWiXiJQK2abV1T2fvH.nIuqCYKNrMDYaz2PHpATswIVDPYsMw/QsG
When print password out of the bcrypt block, then we get plain password not hashed, I know that bcrypt is working and password is hashed successfully but we cannot get hashed password out of the bcrypt block.
Please help me regarding to the same question, I think I misplace code at some point. Thanks in advance.