Created
January 12, 2023 23:09
-
-
Save Bucephalus-lgtm/d71004b4e3f78fad7b4c8d8194db3602 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import bcrypt from bcrypt npm package | |
const bcrypt = require("bcrypt); | |
// Hash the incoming password using bcyrpt | |
// Use it during SIGNUP, thus save the hashed password only in Database | |
async function hashPassword(plaintextPassword) { | |
const hashedPassword = await bcrypt.hash(plaintextPassword, 10); | |
// Now store it in the database instead of plainText password | |
} | |
// Now, compare the password | |
// Use it during LOGIN, compare password saved in DB(hashedPassword) | |
// and the incoming password that is plaintextPassword, since user will obviously insert plaintextPassword, right? | |
async function comparePassword(plaintextPassword, hashedPassword) { | |
const result = await bcrypt.compare(plaintextPassword, hashedPassword); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment