Hash and Compare Passwords Asynchronously
Hints
Hint 1
Use bcrypt’s hash() method to hash a plain text password with a specific number of salt rounds.
Hint 2
Then use bcrypt’s compare() method to compare a plain text password with the results from the hash.
Solutionss
Solution 1 (Click to Show/Hide)
- In the
server.jsfile, add:
bcrypt.hash(myPlaintextPassword, saltRounds, (err, hash) => {
console.log(hash);
bcrypt.compare(myPlaintextPassword, hash, (err, res) => {
console.log(res);
});
});
- Check the console to see the results from the methods.
Note: Be sure to submit the link to the live demo of your project.