Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set minimal score for validation #64

Merged
merged 2 commits into from
Jan 2, 2024
Merged

Conversation

PavelWeirich
Copy link
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.

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
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
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
2 of 7 checks passed
@f3l1x
Copy link
Member

f3l1x commented Jan 2, 2024

👍 Thanks

@bohacf
Copy link

bohacf commented Jan 13, 2024

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
Development

Successfully merging this pull request may close these issues.

3 participants