Creates an hash for a password
@param {String} password
@param {String} [algorithm] - default sha1
@param {String} [salt] - default is generated
@returns {String}
507459
function (password, algorithm, salt) {
            salt = salt || Crypto.randomBytes(128).toString("hex");
            algorithm = algorithm || this.$.algorithm;

            var hash = Crypto.createHash(this.$.algorithm);
            hash.update(salt + password, "utf8");

            return [algorithm, salt, hash.digest("hex")].join(this.$.delimiter);
        }
649463
function hash(sess) {
  // serialize
  var str = JSON.stringify(sess, function (key, val) {
    // ignore sess.cookie property
    if (this === sess && key === 'cookie') {
      return
    }

    return val
  })

  // hash
  return crypto
    .createHash('sha1')
    .update(str, 'utf8')
    .digest('hex')
}
1138125
function hash (str) {
  return crypto
    .createHash('sha1')
    .update(str, 'ascii')
    .digest('base64')
    .replace(PLUS_GLOBAL_REGEXP, '-')
    .replace(SLASH_GLOBAL_REGEXP, '_')
    .replace(EQUAL_GLOBAL_REGEXP, '')
}
958415
function hashToken(token, done) {
  return bcrypt.genSalt(10, function(genSaltErr, salt) {
    if (genSaltErr) {
      return done(genSaltErr);
    }

    bcrypt.hash(token, salt, done);
  });
}
13773
function hash_password(plain_text, salt, callback) {
  // Get the crypto library.
  const crypto = require("crypto")

  // These should be a *slow* as possible, higher = slower.
  // Slow it down until you tweak a bounce change.
  const password_iterations = process.env.PW_GEN_PW_ITERS || 4096

  // Password length and algorithm.
  const password_length = process.env.PW_GEN_PW_LENGTH || 512
  const password_algorithm = process.env.PW_GEN_PW_ALG || "sha256"

  // Create a hash, we're going to encrypt the password.
  // I wish Node had native support for good KDF functions
  // like bcrypt or scrypt but PBKDF2 is good for now.
  crypto.pbkdf2(plain_text, salt, password_iterations, password_length, password_algorithm, (err, key) => {
    // Move on.
    callback(key.toString("hex"), salt)
  })
}
317078
public static function generateHash($password) {
        // A higher "cost" is more secure but consumes more processing power
        $cost = 10;

        // Create a random salt
        $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');

        // Prefix information about the hash so PHP knows how to verify it later.
        // "$2a$" Means we're using the Blowfish algorithm. The following two digits are the cost parameter.
        $salt = sprintf("$2a$%02d$", $cost) . $salt;

        // Value:
        // $2a$10$eImiTXuWVxfM37uY4JANjQ==
        // Hash the password with the salt
        $hash = crypt($password, $salt);

        return $hash;
    }
1015389
function generateBKP (pkp) {
  const buffer = new Buffer(pkp, 'base64')
  const hash = crypto.createHash('sha1')
  hash.update(buffer)
  const sha1str = hash.digest('hex').toUpperCase()
  return sha1str.match(/(.{1,8})/g).join('-')
}
1087985
def encode(password)
      primary = ::Digest::MD5.new
      primary << password
      primary << prefix
      primary << @salt

      md5_t = ::Digest::MD5.digest("#{password}#{@salt}#{password}")

      l = password.length
      while l > 0 do
        slice_size = ( l > DIGEST_LENGTH ) ? DIGEST_LENGTH : l
        primary << md5_t[0, slice_size]
        l -= DIGEST_LENGTH
      end

      # weirdness
      l = password.length
      while l != 0
        case (l & 1)
        when 1
          primary << 0.chr
        when 0
          primary << password[0,1]
        end
        l >>= 1
      end

      pd = primary.digest

      encoded_password = "#{prefix}#{@salt}$"

      # apr_md5_encode has this comment about a 60Mhz Pentium above this loop.
      1000.times do |x|
        ctx = ::Digest::MD5.new
        ctx << (( ( x & 1 ) == 1 ) ? password : pd[0,DIGEST_LENGTH])
        (ctx << @salt) unless ( x % 3 ) == 0
        (ctx << password) unless ( x % 7 ) == 0
        ctx << (( ( x & 1 ) == 0 ) ? password : pd[0,DIGEST_LENGTH])
        pd = ctx.digest
      end


      pd = pd.bytes.to_a

      l = (pd[ 0]<<16) | (pd[ 6]<<8) | pd[12]
      encoded_password << to_64(l, 4)

      l = (pd[ 1]<<16) | (pd[ 7]<<8) | pd[13]
      encoded_password << to_64(l, 4)

      l = (pd[ 2]<<16) | (pd[ 8]<<8) | pd[14]
      encoded_password << to_64(l, 4)

      l = (pd[ 3]<<16) | (pd[ 9]<<8) | pd[15]
      encoded_password << to_64(l, 4)

      l = (pd[ 4]<<16) | (pd[10]<<8) | pd[ 5]
      encoded_password << to_64(l, 4)
      encoded_password << to_64(pd[11],2)

      return encoded_password
    end
746447
function createSHAHash(buffer, algorithm) {
    var logger = getLogger('utility.createSHA1Hash');
    var sha1sum = crypto.createHash(algorithm || 'sha1');
    if (require('util').isArray(buffer)) {
        if (logger.isDebugEnabled()) {
            logger.debug('It\'s an Array of buffers');
        }
        for (var i = 0; i < buffer.length; i++) {
            sha1sum.update(buffer[i]);
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug('It\'s only one buffer');
        }
        sha1sum.update(buffer);
    }
    return sha1sum.digest();
}
1042887
def hash_password(password, salt):
    
    password = str(password).encode('utf-8')
    salt = str(salt).encode('utf-8')
    return hashlib.sha512(password + salt).hexdigest()
626914
protected function protect($password, $salt = null)
    {
        $salt = isset($salt)
            ? $salt
            : $this->salt;

        return $password . $salt;
    }
587247
def hash_password(plaintextpw: str,
                  log_rounds: int = BCRYPT_DEFAULT_LOG_ROUNDS) -> str:
    
    salt = bcrypt.gensalt(log_rounds)  # optional parameter governs complexity
    hashedpw = bcrypt.hashpw(plaintextpw, salt)
    return hashedpw
601373
public function hash(string $password, string $algorithm): string
    {
        return $this->getPasswordHashStrategy($algorithm)->hash($password);
    }
81922
public function hash($password, $salt = null)
    {
        $hash_format = sprintf("$2y$%02d$", $this->cost);

        !$salt && $salt = $this->generateSalt();
        if (strlen($salt) < 22) {
            throw new \InvalidArgumentException(sprintf("Provided salt is too short: %d expecting %d", strlen($salt), 22));
        }

        $hash = $hash_format . $salt;
        $ret = crypt($password, $hash);

        if (!is_string($ret) || strlen($ret) <= 13) {
            return false;
        }

        return $ret;
    }
882788
def generate_password
      if(self.password.nil?)
        self.password = Digest::SHA1.hexdigest(self.username + self.enterprise_id)
      else
        self.password = Digest::SHA1.hexdigest(self.password + self.enterprise_id)
      end
    end
1052088
def _hash_internal(method, salt, password):
    
    if method == "plain":
        return password, method

    if isinstance(password, text_type):
        password = password.encode("utf-8")

    if method.startswith("pbkdf2:"):
        args = method[7:].split(":")
        if len(args) not in (1, 2):
            raise ValueError("Invalid number of arguments for PBKDF2")
        method = args.pop(0)
        iterations = args and int(args[0] or 0) or DEFAULT_PBKDF2_ITERATIONS
        is_pbkdf2 = True
        actual_method = "pbkdf2:%s:%d" % (method, iterations)
    else:
        is_pbkdf2 = False
        actual_method = method

    if is_pbkdf2:
        if not salt:
            raise ValueError("Salt is required for PBKDF2")
        rv = pbkdf2_hex(password, salt, iterations, hashfunc=method)
    elif salt:
        if isinstance(salt, text_type):
            salt = salt.encode("utf-8")
        mac = _create_mac(salt, password, method)
        rv = mac.hexdigest()
    else:
        rv = hashlib.new(method, password).hexdigest()
    return rv, actual_method
1246671
public static function hash($password, $algorithm = PasswordFile::ALG_MD5, array $options = null)
    {
        if ($options === null) {
            $options = [];
        }
        switch ($algorithm) {
            case PasswordFile::ALG_MD5:
                return APR1::hash($password);
            case PasswordFile::ALG_BCRYPT:
                $cost = isset($options['cost']) ? $options['cost'] : null;
                return BCrypt::hash($password, $cost);
            case PasswordFile::ALG_SHA1:
                return self::sha1($password);
            case PasswordFile::ALG_CRYPT:
                return self::cryptHash($password);
            case PasswordFile::ALG_PLAIN:
                return $password;
        }
        return null;
    }