<?php
 class vB_HumanVerify_Recaptcha3 extends vB_HumanVerify { public function verify_token($input, $action) { if (!empty($input['g-recaptcha-response'])) { $options = vB::getDatastore()->getValue('options'); $url = 'https://www.google.com/recaptcha/api/siteverify'; $query = [ 'secret' => $options['hv_recaptcha3_privatekey'], 'remoteip' => vB::getRequest()->getIpAddress(), 'response' => $input['g-recaptcha-response'], ]; $vurl = vB::getUrlLoader(); $vurl->setOption(vB_Utility_Url::CLOSECONNECTION, 1); $result = $vurl->post($url, $query); if ($result === false) { $this->error = 'humanverify_recaptcha_unreachable'; return false; } else { $result = json_decode($result['body'], true); if ($result['success'] !== true) { switch ($result['error-codes'][0]) { case 'missing-input-secret': case 'invalid-input-secret': $this->error = 'humanverify_recaptcha_privatekey'; break; case 'missing-input-response': case 'invalid-input-response': default: $this->error = 'humanverify_recaptcha_parameters'; break; } return false; } $threshold = $options['hv_recaptcha3_threshold_' . $action] ?? 0.5; if (trim($action) != trim($result['action']) OR floatval($result['score']) < $threshold) { $this->error = 'humanverify_recaptcha3_failure'; return false; } return true; } } else { $this->error = 'humanverify_recaptcha_parameters'; return false; } } } 