Skip to content

Commit

Permalink
Move hashing logic to hash method
Browse files Browse the repository at this point in the history
  • Loading branch information
venables committed Feb 13, 2017
1 parent f0d22e3 commit 93b22e4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/secure-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ module.exports = function (Bookshelf) {
return DEFAULT_PASSWORD_FIELD
}

/**
* Generate the BCrypt hash for a given string
*
* @param {String} value - The string to hash
* @returns {String} - A BCrypt hashed version of the string
*/
function hash (value) {
let salt = bcrypt.genSaltSync(DEFAULT_SALT_ROUNDS)

return bcrypt.hashSync(value, salt)
}

/**
* Checks if a string is empty (null, undefined, or length of zero)
*
Expand Down Expand Up @@ -54,9 +66,7 @@ module.exports = function (Bookshelf) {
if (value === null) {
this.set(passwordDigestField, null)
} else if (!isEmpty(value)) {
let salt = bcrypt.genSaltSync(DEFAULT_SALT_ROUNDS)
let digest = bcrypt.hashSync(value, salt)
this.set(passwordDigestField, digest)
this.set(passwordDigestField, hash(value))
}
}
}
Expand Down

0 comments on commit 93b22e4

Please sign in to comment.