Compares two strings in constant time to prevent timing attacks.

Parameters

  • string $left The left side of the comparison.
  • string $right The right side of the comparison.

Returns

boolean Returns a boolean indicating whether the two strings are equal.

Source

						public static function compare($left, $right) {
		$result = true;

		if (($length = strlen($left)) != strlen($right)) {
			return false;
		}
		for ($i = 0; $i < $length; $i++) {
			$result = $result && ($left[$i] === $right[$i]);
		}
		return $result;
	}