Skip to content
Snippets Groups Projects
Unverified Commit efae566c authored by JonGold's avatar JonGold
Browse files

configurable recaptcha threshold

parent 69b8aee3
No related branches found
No related tags found
1 merge request!19configurable recaptcha threshold
......@@ -186,7 +186,7 @@ class Recaptcha {
// reCAPTCHAv3
$recaptcha = new \ReCaptcha\ReCaptcha(\Civi::settings()->get('formprotection_recaptcha_privatekey'));
$resp = $recaptcha
->setScoreThreshold(0.5)
->setScoreThreshold(\Civi::settings()->get('formprotection_recaptcha_threshold'))
->verify($token, Utils::getIPAddress());
if (!$resp->isSuccess()) {
// If Firewall is enabled, log it there
......@@ -378,4 +378,13 @@ class Recaptcha {
return $addCaptcha;
}
public static function validateRecaptchaThreshold(float &$value) : bool {
if ($value < 0) {
$value = 0;
}
if ($value > 1) {
$value = 1;
}
return TRUE;
}
}
......@@ -333,6 +333,31 @@ return [
],
],
],
'formprotection_recaptcha_threshold' => [
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'formprotection_recaptcha_threshold',
'type' => 'float',
'quick_form_type' => 'Element',
'html_attributes' => [
'size' => 10,
'maxlength' => 5,
],
'html_type' => 'text',
'default' => 0.5,
'add' => '5.68',
'title' => E::ts('reCAPTCHA Threshold'),
'is_domain' => 1,
'is_contact' => 0,
'description' => 'reCAPTCHA scores submissions from 0 (definitely a bot) to 1.0 (definitely a human). Lower this number if too many humans are being blocked; raise it if too many bots are being allowed.',
'validate_callback' => '\Civi\Formprotection\Recaptcha::validateRecaptchaThreshold',
'help_text' => NULL,
'settings_pages' => [
'formprotection' => [
'weight' => 215,
],
],
],
'formprotection_recaptcha_privatekey' => [
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment