Last active
April 6, 2020 19:08
-
-
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.
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('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