Skip to content

Instantly share code, notes, and snippets.

@Bucephalus-lgtm
Created January 12, 2023 23:09
Show Gist options
  • Save Bucephalus-lgtm/d71004b4e3f78fad7b4c8d8194db3602 to your computer and use it in GitHub Desktop.
Save Bucephalus-lgtm/d71004b4e3f78fad7b4c8d8194db3602 to your computer and use it in GitHub Desktop.
// 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