public static function timingSafeCompare($known, $unknown)
	{
		// Prevent issues if string length is 0
		$known   .= chr(0);
		$unknown .= chr(0);

		$knownLength   = strlen($known);
		$unknownLength = strlen($unknown);

		// Set the result to the difference between the lengths
		$result = $knownLength - $unknownLength;

		// Note that we ALWAYS iterate over the user-supplied length to prevent leaking length info.
		for ($i = 0; $i < $unknownLength; $i++)
		{
			// Using % here is a trick to prevent notices. It's safe, since if the lengths are different, $result is already non-0
			$result |= (ord($known[$i % $knownLength]) ^ ord($unknown[$i]));
		}

		// They are only identical strings if $result is exactly 0...
		return $result === 0;
	}
public static function timingSafeCompare($known, $unknown)
	{
		// Prevent issues if string length is 0
		$known   .= chr(0);
		$unknown .= chr(0);

		$knownLength   = strlen($known);
		$unknownLength = strlen($unknown);

		// Set the result to the difference between the lengths
		$result = $knownLength - $unknownLength;

		// Note that we ALWAYS iterate over the user-supplied length to prevent leaking length info.
		for ($i = 0; $i < $unknownLength; $i++)
		{
			// Using % here is a trick to prevent notices. It's safe, since if the lengths are different, $result is already non-0
			$result |= (ord($known[$i % $knownLength]) ^ ord($unknown[$i]));
		}

		// They are only identical strings if $result is exactly 0...
		return $result === 0;
	}
public static function timingSafeCompare ( $ known , $ unknown ) { // Prevent issues if string length is 0 $ known .= chr ( 0 ) ; $ unknown .= chr ( 0 ) ; $ knownLength = strlen ( $ known ) ; $ unknownLength = strlen ( $ unknown ) ; // Set the result to the difference between the lengths $ result = $ knownLength - $ unknownLength ; // Note that we ALWAYS iterate over the user-supplied length to prevent leaking length info. for ( $ i = 0 ; $ i < $ unknownLength ; $ i ++ ) { // Using % here is a trick to prevent notices. It's safe, since if the lengths are different, $result is already non-0 $ result |= ( ord ( $ known [ $ i % $ knownLength ] ) ^ ord ( $ unknown [ $ i ] ) ) ; } // They are only identical strings if $result is exactly 0... return $ result === 0 ; }
A timing safe comparison method. This defeats hacking
attempts that use timing based attack vectors.

@param   string   $known    A known string to check against.
@param   string   $unknown  An unknown string to check.
@return  boolean  True if the two strings are exactly the same.
A timing safe comparison method . This defeats hacking attempts that use timing based attack vectors .