Created
January 25, 2018 19:14
-
-
Save KenVega-Tekton/9d7ef1ebd812b2e1afc2248358779ea3 to your computer and use it in GitHub Desktop.
Basic usage of bcrytpjs
This file contains hidden or 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
const bcrypt = require("bcryptjs"); | |
let password = "ThisRepresentsSomePassword123"; | |
/*bcrypt.genSalt(10, (err, salt) => { | |
bcrypt.hash(password, salt, (err, hash) => { | |
console.log(hash); | |
}); | |
});*/ | |
let hashedPassword = | |
"$2a$10$Fj6St8qtxek20BayFKYW1OR3kYN3WErSqp2yx74KjQtaNdgKpkUcq"; | |
let hashedPassword2 = | |
"$2a$10$DafGKsNmwAnBv1Mm0/i86OP0fO2iE.r4exetr3lAw81/QXYjlAwM."; | |
bcrypt.compare(password, hashedPassword2, (err, result) => { | |
console.log(result); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Take a look at the following bcrypt hash I just created:
Let's break this up into it's proper parts:
Now that we know this, we can figure out what happens when someone tries to login to the application. We fetch the user by email and get the password field. The plain text password is then hashed with the 22 char salt. Bcrypt checks to see if that resulting hash is equal to the 31 character hash it has on file. If they're equal, the password was correct.
(this is a response from Andrew on the course Node.js)