Newer
Older
codeigniter4-recaptcha / BaseReCaptchaValidator.php
@denis303 denis303 on 13 Mar 2020 682 bytes n/a
<?php

namespace Denis303\ReCaptcha;

use Denis303\ReCaptcha\Config\ReCaptcha as ReCaptchaConfig;

abstract class BaseReCaptchaValidator
{

    public static function reCaptcha3(string $token, string $params) : bool
    {
        $reCaptcha = service('reCaptcha');

        $params = explode(',', $params);

        $reCaptcha->setExpectedAction(trim($params[0]));

        if (count($params) > 1)
        {
            $reCaptcha->setScoreThreshold(trim($params[1]));
        }
        
        $response = $reCaptcha->verify($token);

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

        return true;
    }

}