Created
December 14, 2019 10:56
-
-
Save orange634nty/a213bac306e4391db5d5e27ea8e2967f 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
{ | |
"name": "test-bycrypt", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"private": null, | |
"dependencies": { | |
"bcrypt": "^1.0.3" | |
} | |
} |
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
var bcrypt = require('bcrypt'); | |
bcrypt.genSalt(10, function(err, salt) { | |
bcrypt.hash("B4c0/\/", salt, function(err, hash) { | |
console.log(hash); | |
// To check a password: | |
bcrypt.compare("B4c0/\/", hash, function(err, res) { | |
// res == true | |
console.log("equal") | |
console.log(res); | |
}); | |
bcrypt.compare("not_bacon", hash, function(err, res) { | |
// res == false | |
console.log("not equal"); | |
console.log(res); | |
}); | |
}); | |
}); | |
// Auto-gen a salt and hash: | |
bcrypt.hash('bacon', 8, function(err, hash) { | |
console.log(hash); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment