Ensures the hash passed in is valid

@param  string  $hash
@param  string  $validation_regex
973135
private function validate($hash, string $validation_regex): void {
    if(!is_string($hash) || preg_match($validation_regex, $hash) === 0) {
      throw new InvalidArgumentException('Expected hash, but got ' . var_export($hash, true) . '] instead');
    }
  }
955769
public static void validate(HppResponse hppResponse, String secret) {
		if (!hppResponse.isHashValid(secret)) {
			LOGGER.error("HppResponse contains an invalid security hash.");
			throw new RealexValidationException("HppResponse contains an invalid security hash");
		}
	}
670588
def _pv_regex(opts, key, regex)
        value = _pv_opts_lookup(opts, key)
        if value != nil
          passes = false
          [ regex ].flatten.each do |r|
            if value != nil
              if r.match(value.to_s)
                passes = true
              end
            end
          end
          unless passes
            raise ValidationFailed, "Option #{key}'s value #{value} does not match regular expression #{regex.inspect}"
          end
        end
      end
1280324
public static function requiresMigration($hash)
    {
        $version = substr($hash, 0, 8);

        if ($version == PBKDF2::PREFIX) { // salted PBKDF2, let the responsible class decide
            return PBKDF2::requiresMigration($hash);
        } else { // everything else
            return true;
        }
    }
478383
public function verify($original, $hash)
    {
        if ($this->verifyAlgorithm && $this->info($hash)['algoName'] !== 'bcrypt') {
            throw new \Exception('This hash does not use bcrypt algorithm', 500);
        }

        return parent::verify($original, $hash);
    }
1162705
private static function validateRegex($value, $pattern, Validator $validator)
    {
        if (!is_string($value) || preg_match($pattern, $value) === 1) {
            return null;
        }

        return error('The value {data} must match the format {parameter}.', $validator);
    }
1195417
public static function ValidRandomHash ($random_hash, $string, $salt, $hmac_key, $secret_key_length = self::SECRET_KEY_LENGTH, $algo = self::DEFAULT_HASH_ALGORITHM) {
		$secret_hash_length = strlen($random_hash) - $secret_key_length;

		$string_seed = hexdec(hash('crc32b', $string));
		$string_seed = str_pad($string_seed, $secret_key_length, $string_seed);

		$salt_seed = hexdec(hash('crc32b', $salt));
		$salt_seed = str_pad($salt_seed, $secret_key_length, $salt_seed);

		$index_list = [];
		for ($i = 0;$i < $secret_key_length;$i++) {
			$index = $string_seed[$i] * $salt_seed[$i] * $i + $string_seed[$i] + 1;
			$index = $index > $secret_hash_length  ? $secret_hash_length % $index : $index;
			if ($index < 1) {
				$index++;
			} else if ($index >= $secret_hash_length) {
				$index--;
			}
			$index_list[] = $index;
		}
		$kr_index_list = $index_list;

		krsort($kr_index_list);

		$secret_key = [];
		$secret_hash = $random_hash;
		foreach ($kr_index_list as $index) {
			$secret_key[] = substr($secret_hash, $index, 1);
			$secret_hash = substr($secret_hash, 0, $index) . substr($secret_hash, $index + 1);
		}
		krsort($secret_key);
		$secret_key = implode('', $secret_key);

		$secret_hash = Hash::HmacString("\\". $string .'_'. $salt .'/'. $hmac_key, $secret_key, $algo);
		for ($i = 0;$i < $secret_key_length;$i++) {
			$secret_hash = substr($secret_hash, 0, $index_list[$i]) . $secret_key[$i] . substr($secret_hash, $index_list[$i]);
		}

		return $random_hash === $secret_hash;
	}
958422
public function responseNotMatches($regex)
    {
        $actual = $this->session->getPage()->getContent();
        $message = sprintf('The pattern %s was found in the HTML response of the page, but it should not.', $regex);

        $this->assert(!preg_match($regex, $actual), $message);
    }
1292789
private static function cryptStandard(
        $hash,
        $crypt_text,
        $method = self::DEFAULT_CHIPPER
    ) {
        /**
         * ------------------------------------
         * Doing convert string
         * ------------------------------------
         */
        $crypt_text = self::rotate($crypt_text, (strlen($hash) % 13));
        $add = 0;
        $iv = self::safeBase64Decode(sha1($method . @time()));
        if (strlen($hash) < strlen($crypt_text)) {
            $crypt_text = substr_replace($crypt_text, $iv, strlen($hash), 0);
        } else {
            $crypt_text = $crypt_text . $iv;
        }
        $div = strlen($crypt_text) / strlen($hash);
        $new_pass = '';
        while ($add <= $div) {
            $new_pass .= $hash;
            $add++;
        }

        $pass_arr = str_split($new_pass);
        $str_arr  = str_split($crypt_text);
        $ascii = '';
        foreach ($str_arr as $key => $asc) {
            $pass_int = ord($pass_arr[$key]);
            $str_int = ord($asc);
            $int_add = $str_int + $pass_int;
            $ascii .= chr(($int_add+strlen($crypt_text)));
        }

        return [
            self::safeBase64Encode($ascii),
            $method, // for what?
            $iv
        ];
    }
2556
public function matches($key, $regex, &$matches = [])
    {
        if (!$this->has($key, self::HAS_ISSET)) {
            return false;
        }

        return (bool) preg_match($regex, $this->get($key), $matches);
    }
967676
private function ValidateHashKey()
        {
            $Name = 'HashKey'; // 參數名稱
            $Value = $this->HashKey; // 參數內容
            $AllowEmpty = false; // 是否允許空值

            if (empty($Value)) {
                // 是否允許空值
                $this->IsAllowEmpty($Name, $AllowEmpty);
            }
        }
1071489
public static function compare($hash1, $hash2): bool {
        if(!is_string($hash1)) {
            $hash1 = (string) $hash1;
        }
        if(!is_string($hash2)) {
            $hash2 = (string) $hash2;
        }
        return hash_equals($hash1, $hash2);
    }
378526
protected static function _check($check, $regex)
	{
		if (is_string($regex) && preg_match($regex, $check))
		{
			return true;
		}
		return false;
	}
459266
public function getInfo($hash) {
    $regex_pattern = '/^\$[a-z, 1-6]{1,6}\$/i';
    preg_match($regex_pattern, $hash, $matches);

    if(sizeof($matches) > 0) {
      list($method) = $matches;
    } else {
      $method = null;
    }

    switch($method) {
      case self::SHA256:
      case self::SHA512:
      case self::PBKDF2:
        $param = array();
        list( , , $params) = explode('$', $hash);
        parse_str($params, $param);
        $info['options'] = $param;
      break;

      case self::BCRYPT;
        list( , , $cost) = explode('$', $hash);
        $info['options'] = array(
          'cost' => $cost,
        );
      break;
    }
    $info['algo'] = $method;
    return $info;
  }
811563
public static function custom($check, $regex = null)
    {
        if ($regex === null) {
            static::$errors[] = 'You must define a regular expression for Validation::custom()';

            return false;
        }

        return static::_check($check, $regex);
    }
1319934
public static function verifyPassword(string $password, string $hash)
    {
        if (\password_verify($password, $hash)) {
            if (\password_needs_rehash($hash, \PASSWORD_DEFAULT)) {
                return self::password($password);
            }

            return true;
        }

        return false;
    }
874672
public static function passwordVerify(string $password, string $hash): bool
    {
        return (Str::length($hash) > 0 && password_verify($password, $hash));
    }