lib/user-model.js
function hash_password(values, next) {
  // If no password was provided, just move on and exit.
  if (!values.password || values.password.length > 1000) {
    return next()
  }

  this
    .findOne(values)
    .then(user => {
      // Create a salt for this user if they don't have one.
      const salt = user && user.salt ? user.salt : utils.create_salt()

      // We're going to encrypt the password.
      utils.hash_password(values.password, salt, (password, salt) => {
        // Apply the hash and salt to the inbound values.
        values.password = password.toString("hex")
        values.salt = salt
        values.requires_password = false


        // Move on.
        next()
      })
    })
    .catch(next)
}
function hash_password(values, next) {
  // If no password was provided, just move on and exit.
  if (!values.password || values.password.length > 1000) {
    return next()
  }

  this
    .findOne(values)
    .then(user => {
      // Create a salt for this user if they don't have one.
      const salt = user && user.salt ? user.salt : utils.create_salt()

      // We're going to encrypt the password.
      utils.hash_password(values.password, salt, (password, salt) => {
        // Apply the hash and salt to the inbound values.
        values.password = password.toString("hex")
        values.salt = salt
        values.requires_password = false


        // Move on.
        next()
      })
    })
    .catch(next)
}
function hash_password ( values , next ) { // If no password was provided, just move on and exit. if ( ! values . password || values . password . length > 1000 ) { return next ( ) } this . findOne ( values ) . then ( user => { // Create a salt for this user if they don't have one. const salt = user && user . salt ? user . salt : utils . create_salt ( ) // We're going to encrypt the password. utils . hash_password ( values . password , salt , ( password , salt ) => { // Apply the hash and salt to the inbound values. values . password = password . toString ( "hex" ) values . salt = salt values . requires_password = false // Move on. next ( ) } ) } ) . catch ( next ) }
Hash a plain text password using PBKDF2 and SHA256.
@param  {Object}   values to be written to the database.
@param  {Function} next callback, used to finish the operation.
@return {void}
Hash a plain text password using PBKDF2 and SHA256 .