public function hashEquals($expected, $generated)
    {
        $expectedLength = strlen($expected);

        if ($expectedLength !== strlen($generated)) {
            return false;
        }

        $res = 0;

        for ($i = 0; $i < $expectedLength; ++$i) {
            $res |= ord($expected[$i]) ^ ord($generated[$i]);
        }

        return $res === 0;
    }
public function hashEquals($expected, $generated)
    {
        $expectedLength = strlen($expected);

        if ($expectedLength !== strlen($generated)) {
            return false;
        }

        $res = 0;

        for ($i = 0; $i < $expectedLength; ++$i) {
            $res |= ord($expected[$i]) ^ ord($generated[$i]);
        }

        return $res === 0;
    }
public function hashEquals ( $ expected , $ generated ) { $ expectedLength = strlen ( $ expected ) ; if ( $ expectedLength !== strlen ( $ generated ) ) { return false ; } $ res = 0 ; for ( $ i = 0 ; $ i < $ expectedLength ; ++ $ i ) { $ res |= ord ( $ expected [ $ i ] ) ^ ord ( $ generated [ $ i ] ) ; } return $ res === 0 ; }
PHP < 5.6 timing attack safe hash comparison

@param string $expected
@param string $generated

@return boolean
PHP < 5 . 6 timing attack safe hash comparison