Validate the response we got from recaptcha.

@return bool true if validation passes
484259
public function validate() {
		$this->buildUrl();

		$json = (new Request($this->url))->run(Config::get('recaptcha.curl'));

		// If we got errors, add them to the errors property.
		if (isset($json->{"error-codes"})) {
			foreach ($json->{"error-codes"} as $key) {
				$this->errors->add($key, Lang::get('recaptcha::validator.' . $key));
			}
		}

		return (bool) $json->success;
	}
60910
public function checkChallenge()
    {
        $request  = new CheckChallenge();

        /** @var CheckChallengeResponse $response */
        $response     =  $this->service->execute($request, $this->position);
        $challengeUrl = trim($response->getChallengeUrl());

        if ($response->getShowChallenge() || !empty($challengeUrl)) {
            if (!$this->captchaSolver instanceof Solver) {
                $this->getLogger()->alert("Account has been flagged for CAPTCHA. No CAPTCHA-solver defined, returning challenge.");
                return $challengeUrl;
            }

            $this->getLogger()->alert("Account has been flagged for CAPTCHA. Attempting to solve CAPTCHA with defined resolver.");

            /* Attempt to solve CAPTCHA */
            $token = $this->captchaSolver->solve($challengeUrl);
            $this->getLogger()->info("Received CAPTCHA solution. Verifying...");

            /* Wait 1 second before firing verification request. */
            sleep(1);
            $verify = $this->verifyChallenge($token);

            if ($verify->hasSuccess()) {
                $this->getLogger()->info("Successfully solved CAPTCHA.");
                return true;
            }

            throw new FailedCaptchaException("Failed to resolve CAPTCHA.");
        }

        return false;
    }
553389
public function validate()
    {
        return (
            (
                filter_var($this->uri, FILTER_VALIDATE_URL) ||
                // PHP 5.x bug fix: FILTER_VALIDATE_URL doesn't support IPv6 urls. IP check not needed in the future.
                $this->validateIP(($parsed = parse_url($this->uri, PHP_URL_HOST)) === false ? '' : $parsed)
            ) &&
            ($parsed = parse_url($this->uri)) !== false &&
            (
                $this->validateHost($parsed['host']) ||
                $this->validateIP($parsed['host'])
            ) &&
            $this->validateScheme($parsed['scheme'])
        );
    }
1246997
public function verifyRequest(Request $request = null)
    {
        $request = $request ?: $this->request;
        $response = $request->request->get('g-recaptcha-response');
        $remoteip = $request->getClientIp();

        return $this->verify($response, $remoteip);
    }
1223398
public function validate()
    {
        if ($this->_amount === null) {
            $this->setValidationError('Payment amount not specified');
            return false;
        }

        $value = $this->_amount->getValue();
        if (empty($value) || $value <= 0.0) {
            $this->setValidationError('Invalid payment amount value: '.$value);
            return false;
        }

        if ($this->_receipt !== null && $this->_receipt->notEmpty()) {
            $email = $this->_receipt->getEmail();
            $phone = $this->_receipt->getPhone();
            if (empty($email) && empty($phone)) {
                $this->setValidationError('Both email and phone values are empty in receipt');
                return false;
            }
        }

        return true;
    }
440268
private function _hasRecaptcha()
    {
        $action = AnRequest::get('post.action', 'cmd', 'add');

        if ($action == 'add' && $this->_id === 0) {
            if ($this->_option === 'com_people' && $this->_viewer->guest()) {
                if ($this->_view === 'session') {
                    return true;
                }
                if ($this->_view === 'person') {
                    return true;
                }
            }

            if ($this->_option === 'com_groups' && $this->_view === 'group') {
                return true;
            }
        }

        return false;
    }
255755
protected function _validateInput()
    {
        $result = true;

        $oxid = $this->getEditObjectId();
        $parameters = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editval");

        // if creating new language, checking if language already exists with
        // entered language abbreviation
        if (($oxid == -1) && $this->_checkLangExists($parameters['abbr'])) {
            $this->addDisplayException('LANGUAGE_ALREADYEXISTS_ERROR');
            $result = false;
        }

        // As the abbreviation is used in database view creation, check for allowed characters
        if (!$this->checkAbbreviationAllowedCharacters($parameters['abbr'])) {
            $this->addDisplayException('LANGUAGE_ABBREVIATION_INVALID_ERROR');
            $result = false;
        }

        // checking if language name is not empty
        if (empty($parameters['desc'])) {
            $this->addDisplayException('LANGUAGE_EMPTYLANGUAGENAME_ERROR');
            $result = false;
        }

        return $result;
    }
1162448
public function validate()
    {
        if (!$this->validationHash) {
            return false;
        }
        $db = Database::connection();
        $row = $db->GetRow("select * from MailValidationHashes where mHash = ? order by mDateGenerated desc limit 1", $this->validationHash);
        if ($row['mvhID'] > 0) {
            // Can't do this even though it's a good idea
            //if ($row['email'] != $this->sender) {
            //	return false;
            //} else {
                return $row['mDateRedeemed'] == 0;
            //}
        }
    }
741635
public function checkResponse()
    {
        if (!isset($this->order_ref)) {
            $this->errorMessage[] = 'CHECK RESPONSE: Missing order_ref variable!';
            return false;
        }
        $this->logFunc("BackRef", $this->getData, $this->order_ref);

        if (!$this->checkCtrl()) {
            $this->errorMessage[] = 'CHECK RESPONSE: INVALID CTRL!';
            return false;
        }

        $ios = new SimpleIos($this->iosConfig, $this->getData['order_currency'], $this->order_ref);

        foreach ($ios->errorMessage as $msg) {
            $this->errorMessage[] = $msg;
        }
        foreach ($ios->debugMessage as $msg) {
            $this->debugMessage[] = $msg;
        }

        if (is_object($ios)) {
            $this->checkIOSStatus($ios);
        }
        $this->logFunc("BackRef_BackStatus", $this->backStatusArray, $this->order_ref);
        if (!$this->checkRtVariable($ios)) {
            return false;
        }
        if (!$this->backStatusArray['RESULT']) {
            return false;
        }
        return true;
    }
543193
public function check(Request $request, Response $response) {
        $actual = $request->getStage('g-recaptcha-response');
        $config = $this->app->package('global')->service('captcha-main');

        //if no config
        if(!$config
            || !isset($config['token'], $config['secret'])
            || $config['token'] === '<GOOGLE CAPTCHA TOKEN>'
            || $config['secret'] === '<GOOGLE CAPTCHA SECRET>'
        )
        {
            //let it pass
            $this->app->subflow($this->yes, $request, $response);
            return $this;
        }

        $result = CurlHandler::i()
            ->setUrl(self::END_POINT)
            ->verifyHost(false)
            ->verifyPeer(false)
            ->setPostFields(http_build_query(array(
                'secret' => $config['secret'],
                'response' => $actual
            )))
            ->getJsonResponse();

        if(!isset($result['success']) || !$result['success']) {
            //prepare to error
            $message = $this->app->package('global')->translate(static::ATTACK);
            $response->setError(true, $message);

            //and trigger a subflow
            $this->app->subflow($this->no, $request, $response);
            return $this;
        }

        //it passed
        $this->app->subflow($this->yes, $request, $response);
        return $this;
    }
656059
protected function validateKeyCredential()
    {
        if (!$this->isPosted('save')) {
            return false;
        }

        $this->setSubmitted('credential');
        $this->validateElement(array('name' => $this->text('Name')), 'length', array(1, 255));
        $this->validateElement(array('data.key' => $this->text('Key')), 'length', array(1, 255));

        return !$this->hasErrors();
    }
344008
public function validate()
    {
        $confirmationInput = $this->inputName.'_confirmation';

        if (isset($this->input[$confirmationInput]) &&
            $this->input[$confirmationInput] == $this->getValue()) {
            return true;
        }

        return false;
    }
192612
protected function validate()
    {
        $this->data = $this->module->getInfo($this->module_id);

        if (empty($this->data)) {
            $this->error = $this->translation->text('Failed to read module @id', array('@id' => $this->module_id));
            return false;
        }

        try {
            $this->module_model->checkCore($this->data);
            $this->module_model->checkPhpVersion($this->data);
            return true;
        } catch (Exception $ex) {
            $this->error = $ex->getMessage();
            return false;
        }
    }
1337103
protected function isTokenValid() {
    if ($this->isTokenValid) {
      // already validated
      return true;
    }
    $request = ObjectFactory::getInstance('request');
    $token = $request->hasHeader(self::TOKEN_HEADER) ? $request->getHeader(self::TOKEN_HEADER) :
        $request->getValue(self::TOKEN_HEADER, null);
    $this->isTokenValid = $token != null && $token == $_COOKIE[$this->tokenName];
    return $this->isTokenValid;
  }
808445
public function verify($responsestr) {
        global $CFG;
        require_once($CFG->libdir . '/recaptchalib_v2.php');

        $response = recaptcha_check_response(RECAPTCHA_VERIFY_URL, $CFG->recaptchaprivatekey,
                                           getremoteaddr(), $responsestr);
        if (!$response['isvalid']) {
            $attributes = $this->getAttributes();
            $attributes['error_message'] = $response['error'];
            $this->setAttributes($attributes);
            return $response['error'];
        }
        return true;
    }
93463
public function validate(): bool
    {
        $valid = true;
        foreach ($this->_responses as $key => $response) {
            if ($response === null) {
                continue;
            }
            if (!$response->validate()) {
                $valid = false;
            }
        }
        return $valid && empty($this->_errors);
    }
194969
protected function validate(): bool
    {
        $A2 = $this->request->getMethod().':'.$this->digestParts['uri'];

        if ('auth-int' === $this->digestParts['qop']) {
            // Making sure we support this qop value
            if (!($this->qop & self::QOP_AUTHINT)) {
                return false;
            }
            // We need to add an md5 of the entire request body to the A2 part of the hash
            $body = $this->request->getBody($asString = true);
            $this->request->setBody($body);
            $A2 .= ':'.md5($body);
        } elseif (!($this->qop & self::QOP_AUTH)) {
            return false;
        }

        $A2 = md5($A2);

        $validResponse = md5("{$this->A1}:{$this->digestParts['nonce']}:{$this->digestParts['nc']}:{$this->digestParts['cnonce']}:{$this->digestParts['qop']}:{$A2}");

        return $this->digestParts['response'] === $validResponse;
    }