Skip to content

Commit c6abf4b

Browse files
authored
Adds Prosopo Procaptcha support
* Adds Prosopo Procaptcha as captcha provider
1 parent 0fa2e5d commit c6abf4b

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/Captcha/Captcha.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@
33

44
use App\Captcha\Providers\HCaptchaProvider;
55
use App\Captcha\Providers\ReCaptchaProvider;
6+
use App\Captcha\Providers\ProcaptchaProvider;
67

78
final class Captcha
89
{
910
public const CAPTCHA_PROVIDER_RECAPTCHA = 0;
1011
public const CAPTCHA_PROVIDER_HCAPTCHA = 1;
12+
public const CAPTCHA_PROVIDER_PROCAPTCHA = 2;
1113

1214
public function getProviders(): array
1315
{
1416
return [
1517
self::CAPTCHA_PROVIDER_RECAPTCHA => new ReCaptchaProvider(),
1618
self::CAPTCHA_PROVIDER_HCAPTCHA => new HCaptchaProvider(),
19+
self::CAPTCHA_PROVIDER_PROCAPTCHA => new ProcaptchaProvider()
1720
];
1821
}
1922

2023
public function getProvider(int $provider): ?CaptchaProviderInterface
2124
{
2225
return $this->getProviders()[$provider] ?? null;
2326
}
24-
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
namespace App\Captcha\Providers;
3+
4+
use App\Captcha\CaptchaProviderInterface;
5+
6+
class ProcaptchaProvider implements CaptchaProviderInterface
7+
{
8+
private string $verifyUrl = 'https://api.procaptcha.io/siteverify';
9+
10+
public function validate(string $response, string $secretKey, ?string $userIp = null): bool
11+
{
12+
if (empty($response)) {
13+
return false;
14+
}
15+
16+
$data = [
17+
'captcha' => $response,
18+
'maxVerifiedTime' => 60,
19+
];
20+
21+
$options = [
22+
'http' => [
23+
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
24+
'method' => 'POST',
25+
'content' => http_build_query($data)
26+
]
27+
];
28+
29+
$context = stream_context_create($options);
30+
$response = file_get_contents($this->verifyUrl, false, $context);
31+
if ($response === false) {
32+
return false;
33+
}
34+
35+
$result = json_decode($response);
36+
return $result->success;
37+
}
38+
39+
public function getName(): string
40+
{
41+
return 'Procaptcha';
42+
}
43+
44+
public function getHomePageUrl(): string
45+
{
46+
return 'https://www.prosopo.io/?utm_source=phpform&utm_medium=plugin&utm_campaign=phpform';
47+
}
48+
49+
public function getDocumentationUrl(): string
50+
{
51+
return 'https://github.com/prosopo/captcha/blob/main/README.md';
52+
}
53+
}

0 commit comments

Comments
 (0)