Skip to content

Instantly share code, notes, and snippets.

@alejandrosaenz117
Last active April 6, 2020 19:08
Show Gist options
  • Select an option

  • Save alejandrosaenz117/e16fe650af4a04044768d216f39f0492 to your computer and use it in GitHub Desktop.

Select an option

Save alejandrosaenz117/e16fe650af4a04044768d216f39f0492 to your computer and use it in GitHub Desktop.
This is a simple node function that generates a hash from a plaintext value using the Bcrypt library.
const bcrypt = require('bcrypt');
/**
* @description Generate bcrypt hash from plaintext value
* @param {String} password
* @returns hashed password
*/
const plainTextPassword = 'changeMe';
const saltRounds = 10;
bcrypt.genSalt(saltRounds, (saltErr, salt) => {
if (saltErr) {
return Error('Bcrypt generate salt failed: ' + saltErr);
} else {
bcrypt.hash(plainTextPassword, salt, (hashErr, hash) => {
if (hashErr) {
return Error('Bcrypt hash failed: ' + hashErr);
} else {
console.log(hash);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment