Checks the code given by the captcha

@param string $response Response code after submitting form (usually $_POST['g-recaptcha-response'])
@return bool
163062
public function isValid($response)
    {
        if (is_null($this->secretKey))
            throw new \Exception('You must set your secret key');

        if (empty($response)) {

            $this->errorCodes = array('internal-empty-response');

            return false;
        }

        $params = array(
            'secret'   => $this->secretKey,
            'response' => $response,
            'remoteip' => $this->remoteIp,
        );

        $url = self::VERIFY_URL.'?'.http_build_query($params);

        if (function_exists('curl_version'))
        {
            $curl = curl_init($url);
            curl_setopt($curl, CURLOPT_HEADER, false);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_TIMEOUT, $this->verifyTimeout);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            $response = curl_exec($curl);
        }
        else
        {
            $response = file_get_contents($url);
        }

        if (empty($response) || is_null($response) || !$response)
        {
            return false;
        }

        $json = json_decode($response, true);

        if (isset($json['error-codes']))
        {
            $this->errorCodes = $json['error-codes'];
        }

        return $json['success'];
    }
764899
public function isFlagResponse($response){
        $result = false;

        if($response->getResponseCode() == CheckoutApi_Client_Constant::RESPONSE_CODE_APPROVED_RISK){
            $result = array(
                'responseMessage' => $response->getResponseMessage(),
            );
        }

        return $result;
    }
835032
protected function verifyRequest() : bool
    {
        if (!$this->request->has('g-recaptcha-response')) {
            $this->redirectMessage = 'Recaptcha was not completed';

            return false;
        }

        $data = $this->getRecaptchaResult();

        $success = isset($data->success) ? (bool) $data->success : false;

        if ($success) {
            return true;
        }

        $this->redirectMessage = 'Recaptcha was invalid';

        return false;
    }
990232
protected function checkReCaptcha($captcha_response)
    {
        if (empty($this->recaptcha_config)) return true;

        if ($this->recaptcha_config['recaptcha_enabled']) {

            if (empty($this->recaptcha_config['recaptcha_secret_key'])) throw new \RuntimeException('No secret provided');
            if (!is_string($this->recaptcha_config['recaptcha_secret_key'])) throw new \RuntimeException('The provided secret must be a string');

            $recaptcha = new ReCaptcha($this->recaptcha_config['recaptcha_secret_key']);
            $checkout = $recaptcha->verify($captcha_response, $this->getIp());

            if (!$checkout->isSuccess()) {
                return false;
            }
        }

        return true;
    }
687765
protected function isHtmlResponse($response)
    {
        return strtolower(substr($response, 0, strlen('<!doctype html'))) === '<!doctype html'
            || strtolower(substr($response, 0, strlen('<html'))) === '<html'
            || strtolower(substr($response, 0, strlen('<body'))) === '<body';
    }
704165
private function isErroneousResponse($response)
    {
        return (isset($response->type) and isset($response->title) and isset($response->status) and isset($response->detail));
    }
189366
protected function getVerificationResult($response)
    {
        if (!isset($this->verificationResult[$response])) {
            $postFields = [
                'secret'   => $this->secretKey,
                'response' => $response,
            ];

            if ($this->ip) {
                $postFields['remoteip'] = $this->ip;
            }

            $handle = \curl_init(self::VERIFY_URL);

            \curl_setopt($handle, CURLOPT_POST, \count($postFields));
            \curl_setopt($handle, CURLOPT_POSTFIELDS, \http_build_query($postFields));
            \curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);

            \curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0);
            \curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 0);

            $result = \curl_exec($handle);

            if (!$result || !\is_string($result)) {
                return [];
            }

            $this->verificationResult[$response] = \json_decode($result, true);
        }

        return $this->verificationResult[$response];
    }
831343
private function verifyResponseMac(Response $response)
    {
        $macSource = $this->getMacSource($response);
        $macValue = $response->getParam('VK_MAC');
        $certPath = $this->getPkcCertPath();

        $isVerified = $this->verifySignatureWithCertificate($certPath, $macSource, base64_decode($macValue));

        return (bool)$isVerified;
    }
243619
def submit(recaptcha_response_field,
           secret_key,
           remoteip,
           verify_server=VERIFY_SERVER):
    

    if not (recaptcha_response_field and len(recaptcha_response_field)):
        return RecaptchaResponse(
            is_valid=False,
            error_code='incorrect-captcha-sol'
        )

    def encode_if_necessary(s):
        if isinstance(s, unicode):
            return s.encode('utf-8')
        return s

    params = urllib.urlencode({
        'secret': encode_if_necessary(secret_key),
        'remoteip': encode_if_necessary(remoteip),
        'response': encode_if_necessary(recaptcha_response_field),
    })

    request = Request(
        url="https://%s/recaptcha/api/siteverify" % verify_server,
        data=params,
        headers={
            "Content-type": "application/x-www-form-urlencoded",
            "User-agent": "noReCAPTCHA Python"
        }
    )

    httpresp = urlopen(request)

    return_values = json.loads(httpresp.read())
    httpresp.close()

    return_code = return_values['success']
    error_codes = return_values.get('error-codes', [])

    if return_code:
        return RecaptchaResponse(is_valid=True)
    else:
        return RecaptchaResponse(
            is_valid=False,
            error_code=error_codes
        )
507052
private function _parseResponse($response) {
    list($headerContent, ) = explode("\r\n\r\n", $response);
    $header = $this->_parseHttpSocketHeader($headerContent);
    $response = trim(stristr($response, "\r\n\r\n"), "\r\n");

    $ret = array();
    $ret["result"] =
        (isset($header['Content-Encoding']) &&
         trim($header['Content-Encoding']) == 'gzip') ?
        $this->_gzdecode($response, $header) : $this->_checkChunk($response, $header);
    $ret["info"]["http_code"] =
        isset($header["http_code"]) ? $header["http_code"] : 0;
    $ret["info"]["headers"] = $header;

    return $ret;
  }
524250
private function getHttpResponse(&$header, &$response)
    {
        if (isset($header) && is_array($header) && (0 < count($header))) {
            $response = new HttpResponse($header);
            return true;
        }

        return false;
    }
877283
private function decodeResponse(string $response)
    {
        if (strpos($response, '!') !== false) {
            throw new \Exception($response);
        }

        return new BotScoutResponse($response);
    }
716105
public function verify($response)
    {
        if (!$this->secretKey) {
            throw new Exception('Missing secret key');
        }

        $params = array(
            'secret' => $this->secretKey,
            'response' => $response,
        );

        if ($this->ip !== null) {
            $params['remoteip'] = $this->ip;
        }

        $this->httpClient->setUri(self::VERIFY_SERVER);
        $this->httpClient->setParameterPost($params);

        if ($this->options) {
            $this->httpClient->setOptions($this->options);
        }

        $this->httpClient->setMethod('POST');
        $response = $this->httpClient->send();

        return new CaptchaResponse($response);
    }
1133405
public function checkResponse($response) {
    if (!is_array($response)) {
      return FALSE;
    }

    $responseParams = array();
    foreach ($this->responseFields as $k => $mandatory) {
      if (isset($response[$k])) {
        $responseParams[$k] = $response[$k];
      }
      elseif (!isset($response[$k]) && $mandatory) {
        throw new \Exception('expected response field ' . $k . ' is missing');
      }
    }

    return $responseParams;
  }
198329
public function validateResponse(array $response)
    {
        $returnValue = false;
        if (isset($response['header'])
            && isset($response['header']['status'])
            && $response['header']['status'] >= 200
            && $response['header']['status'] < 300
        ) {
            $returnValue = true;
        }

        return $returnValue;
    }
1310114
public function validateResponse($response)
    {
        if ($response === false) {
            throw new Exception(
                'Error reading data from the server.',
                Exception::SERVER_READ
            );
        }

        if ($response === 'BAD_FORMAT') {
            throw new Exception(
                'The client sent a command line that was not well-formed. ' .
                'This can happen if the line does not end with \r\n, if non-numeric ' .
                'characters occur where an integer is expected, if the wrong number of ' .
                'arguments are present, or if the command line is mal-formed in any other way.',
                Exception::BAD_FORMAT
            );
        }

        if ($response === 'OUT_OF_MEMORY') {
            throw new Exception(
                'The server cannot allocate enough memory for the job. The client should try again later.',
                Exception::OUT_OF_MEMORY
            );
        }

        if ($response === 'UNKNOWN_COMMAND') {
            throw new Exception(
                'The client sent a command that the server does not know.',
                Exception::UNKNOWN_COMMAND
            );
        }

        if ($response === 'INTERNAL_ERROR') {
            throw new Exception(
                'This indicates a bug in the server. It should never happen. ' .
                'If it does happen, please report it at http://groups.google.com/group/beanstalk-talk.',
                Exception::INTERNAL_ERROR
            );
        }

        return true;
    }
827669
public function verify()
    {
        if (!$this->_config['enable']) {
            return true;
        }

        $controller = $this->_registry->getController();
        if ($controller->request->getData('g-recaptcha-response')) {
            $response = json_decode($this->apiCall());

            if (isset($response->success)) {
                return $response->success;
            }
        }

        return false;
    }