Skip to content

Instantly share code, notes, and snippets.

@orange634nty
Created December 14, 2019 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orange634nty/a213bac306e4391db5d5e27ea8e2967f to your computer and use it in GitHub Desktop.
Save orange634nty/a213bac306e4391db5d5e27ea8e2967f to your computer and use it in GitHub Desktop.
{
"name": "test-bycrypt",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": null,
"dependencies": {
"bcrypt": "^1.0.3"
}
}
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