Created
December 7, 2017 21:32
-
-
Save wesleybliss/ac1ddc4e89353d26e0985405bd612465 to your computer and use it in GitHub Desktop.
Bcrypt helpers for hashing passwords
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
'use strict' | |
const bcrypt = require('bcrypt') | |
const BCRYPT_SALT_ROUNDS = 10 | |
/** | |
* Creates a hash of a string using default bcrypt config | |
* | |
* @param {String} password Password or any string to be hashed | |
* @return {Promise} Error or {String} hash | |
*/ | |
const createHash = password => | |
// return bcrypt.hashSync(password, bcrypt.genSaltSync(BCRYPT_SALT_ROUNDS), null) | |
bcrypt.hash(password, BCRYPT_SALT_ROUNDS) | |
/** | |
* Validates a string against a hash | |
* | |
* @param {String} password Password or any string to compare with [hash] | |
* @param {String} hash Hash to compare with [password] | |
* @return {Boolean} True if hash & hashed password match | |
*/ | |
const validateHash = (password, hash) => | |
// return bcrypt.compareSync(password, this.password) | |
bcrypt.compare(password, hash) | |
module.exports.createHash = createHash | |
module.exports.validateHash = validateHash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment