From 4039d125f811bccfc1280f788f9dff30386cb080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ko=C5=A1t=C3=AD=C5=99=20Miloslav?= Date: Mon, 13 Mar 2023 13:17:06 +0100 Subject: [PATCH 1/2] Google recaptcha - option threshold in config --- README.md | 1 + config/captcha.php | 1 + src/Recaptcha.php | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 001b8bf..528ecb8 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ return [ 'invisible' => false, 'hide_badge' => false, 'enable_api_routes' => false, + 'threshold' => 0.5, ]; ``` diff --git a/config/captcha.php b/config/captcha.php index 650c6f4..ff569d5 100644 --- a/config/captcha.php +++ b/config/captcha.php @@ -12,4 +12,5 @@ 'invisible' => false, 'hide_badge' => false, 'enable_api_routes' => false, + 'threshold' => 0.5, ]; diff --git a/src/Recaptcha.php b/src/Recaptcha.php index b2d60c5..fbf76cf 100644 --- a/src/Recaptcha.php +++ b/src/Recaptcha.php @@ -38,4 +38,15 @@ public function renderHeadTag() 'hide_badge' => config('captcha.hide_badge'), ])->render(); } + + public function validResponse() + { + $valid = parent::validResponse(); + $threshold = config('captcha.threshold'); + $score = $this->data->get('score'); + if ($valid && $threshold !== null && $score !== null) { + $valid = ($score >= $threshold); + } + return $valid; + } } From 57f87a60341f849af5848375838a0a56e6e4e19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ko=C5=A1t=C3=AD=C5=99=20Miloslav?= Date: Mon, 13 Mar 2023 13:28:11 +0100 Subject: [PATCH 2/2] Threshold - nicer if --- src/Recaptcha.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Recaptcha.php b/src/Recaptcha.php index fbf76cf..3348591 100644 --- a/src/Recaptcha.php +++ b/src/Recaptcha.php @@ -44,8 +44,8 @@ public function validResponse() $valid = parent::validResponse(); $threshold = config('captcha.threshold'); $score = $this->data->get('score'); - if ($valid && $threshold !== null && $score !== null) { - $valid = ($score >= $threshold); + if ($valid && $threshold !== null && $score !== null && $score < $threshold) { + $valid = false; } return $valid; }