Hash a password using CRYPT algorithm

@param string $password
@return string
161110
public static function cryptHash($password)
    {
        $salt = substr(base64_encode(chr(mt_rand(0, 255))), 0, 2);
        $salt = str_replace('+', '.', $salt);
        return crypt($password, $salt);
    }
512178
protected function normalizePassword($password)
    {
        $obj = [];

        if (is_array($password)) {
            $obj['id'] = $password['id'];
            $obj['encryption'] = (isset($password['secret']) && $password['secret'] !== null)
                ? $password['secret']
                : $password['encryption'];
            $obj['integrity'] = (isset($password['secret']) && $password['secret'] !== null)
                ? $password['secret']
                : $password['integrity'];
        } else { // password is a string
            $obj['encryption'] = $password;
            $obj['integrity'] = $password;
        }

        return $obj;
    }
805051
public static function passwordReHash($password = '', $hash = '')
    {
        if (self::verifyPassword($password, $hash)) {
            if (password_needs_rehash($hash, self::ALGORITHM_DEFAULT)) {
                return self::createPassword($password);
            }
        }

        return NULL;
    }
1157750
public function needsRehash(string $password): bool
    {
        return password_needs_rehash($password, $this->hashType, $this->hashOptions);
    }
601373
public function hash(string $password, string $algorithm): string
    {
        return $this->getPasswordHashStrategy($algorithm)->hash($password);
    }
1058454
function ntPasswordHash($password = null)
    {
        if (isset($password)) {
            return pack('H*',hash('md4', $this->str2unicode($password)));
        } else {
            return pack('H*',hash('md4', $this->str2unicode($this->password)));
        }
    }
1145069
protected function encodePassword($password)
    {
        $passwordSalted = $this->saltPassword($password);
        $passwordEncoded = password_hash($passwordSalted, PASSWORD_DEFAULT);
        
        return $passwordEncoded;
    }
794852
public function hash(string $password)
    {
        $algorithm = $this->config->dget('algorithm', PASSWORD_DEFAULT);
        $options['cost'] = $this->config->dget('cost', 10);

        return password_hash($password, $algorithm, $options);
    }
51399
function CheckAdminPassword(
      $password
  ) {
      return ($this->GetConfigAttribute('admin_password_hash') == md5($this->GetHashSalt().$password.$this->GetHashSalt()));
  }
493709
public function verify($password, $hash)
	{
		// Check if the hash is a blowfish hash.
		if (substr($hash, 0, 4) == '$2a$' || substr($hash, 0, 4) == '$2y$')
		{
			if (version_compare(PHP_VERSION, '5.3.7') >= 0)
			{
				$type = '$2y$';
			}
			else
			{
				$type = '$2a$';
			}

			$hash = $type . substr($hash, 4);

			return (crypt($password, $hash) === $hash);
		}

		// Check if the hash is an MD5 hash.
		if (substr($hash, 0, 3) == '$1$')
		{
			return (crypt($password, $hash) === $hash);
		}

		// Check if the hash is a Joomla hash.
		if (preg_match('#[a-z0-9]{32}:[A-Za-z0-9]{32}#', $hash) === 1)
		{
			return md5($password . substr($hash, 33)) == substr($hash, 0, 32);
		}

		return false;
	}
1326906
public static function hash(string $password, int $cost = 11): string
    {
        // $bytes = \random_bytes(17);
        $bytes = \openssl_random_pseudo_bytes(17, $cStrong);

        if (false === $bytes || false === $cStrong) {
            throw new \RuntimeException('exec gen hash error!');
        }

        /* To generate the salt, first generate enough random bytes. Because
         * base64 returns one character for each 6 bits, the we should generate
         * at least 22*6/8=16.5 bytes, so we generate 17. Then we get the first
         * 22 base64 characters
         */
        $salt = substr(base64_encode($bytes), 0, 22);
        /* As blowfish takes a salt with the alphabet ./A-Za-z0-9 we have to
         * replace any '+' in the base64 string with '.'. We don't have to do
         * anything about the '=', as this only occurs when the b64 string is
         * padded, which is always after the first 22 characters.
         */
        $salt = str_replace('+', '.', $salt);
        /* Next, create a string that will be passed to crypt, containing all
         * of the settings, separated by dollar signs
         */
        $param = '$' . implode('$', [
                '2x', //select the most secure version of blowfish (>=PHP 5.3.7)
                str_pad($cost, 2, '0', STR_PAD_LEFT), //add the cost in two digits
                $salt //add the salt
            ]);

        //now do the actual hashing
        return crypt($password, $param);
    }
1191505
public static function hash($password)
    {
        return Yii::$app->security->generatePasswordHash($password, Yii::$app->settings->get('cost', 'user', 10));
    }
746117
public static function getSaltedPasswordHash($password)
    {
        return hash('sha512', \App\Registry::$config->salt . md5($password) . $password . 'sltd');
    }
181011
public static function hashPassword($password)
    {
        # Test the message and key for string validity.
        Helpers::isString($password, 'Hash', 'hashPassword');

        return \Sodium\crypto_pwhash_scryptsalsa208sha256_str(
            $password,
            Constants::PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_INTERACTIVE,
            Constants::PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_INTERACTIVE
        );
    }
473593
public function createPasswordHash($password)
    {
        try {
            return $this->driverInstance->createPasswordHash($password);
        } catch (\Exception $e) {
            throw new CryptException($e->getMessage());
        }
    }
824798
public function hash($password) {
        $random = openssl_random_pseudo_bytes(6);

        $hash = $this->cryptPrivate($password, $this->gensaltPrivate($random));
        if (strlen($hash) == 34) {
            return $hash;
        }

        return '';
    }
598439
public static function create($password): string
    {
        if (!$password) {
            throw new \RuntimeException('Password hashing failed: no password provided.');
        }

        $hash = password_hash($password, PASSWORD_DEFAULT);

        if (!$hash) {
            throw new \RuntimeException('Password hashing failed: internal error.');
        }

        return $hash;
    }