Skip to content

Set minimal score for validation - #64

Merged
f3l1x merged 2 commits into
contributte:masterfrom
MakeArt:master
Jan 2, 2024
Merged

Set minimal score for validation#64
f3l1x merged 2 commits into
contributte:masterfrom
MakeArt:master

Conversation

@PavelWeirich

Copy link
Copy Markdown
Contributor

For better spam filtering, you can use the score returned by Google. The score is in range 0..1 (1.0 is very likely a good interaction, 0.0 is very likely a bot).

How to use it?

Global settings for all forms in config.neon

recaptcha:
	secretKey: <secretKey>
	siteKey: <siteKey>
	minimalScore: 0.5

Or you can define it for each form separately.

$form->addInvisibleReCaptcha('recaptcha')
	->setMinimalScore(0.6);

Or you can have the score set globally and then set it differently for some forms.
The score set in the form has a higher priority.

Comment thread src/Forms/InvisibleReCaptchaField.php Outdated
public function setMinimalScore(float $score): self
{
if ($score < 0 || $score > 1) {
throw new InvalidScoreException('Minimal score expects to be in range 0..1 (1.0 is very likely a good interaction, 0.0 is very likely a bot).');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use LogicException? There is no need to have a custom class for this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@f3l1x
f3l1x merged commit 06ac468 into contributte:master Jan 2, 2024
@f3l1x

f3l1x commented Jan 2, 2024

Copy link
Copy Markdown
Member

👍 Thanks

@bohacf

bohacf commented Jan 13, 2024

Copy link
Copy Markdown

See issue #65 , in reCaptcha 2 is problem with nonexisting $answer['score']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants