Conditions | 3 |
Paths | 2 |
Total Lines | 13 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 0 |
1 | <?php |
||
29 | public function verifyReCaptcha(string $reCaptchaResponse, SecurityType $exceptionType): bool |
||
30 | { |
||
31 | $url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . |
||
32 | urlencode($this->googleSettings['recaptcha']) . '&response=' . urlencode($reCaptchaResponse); |
||
33 | $verificationResponse = file_get_contents($url); |
||
34 | if ( |
||
35 | $verificationResponse !== false |
||
36 | && json_decode($verificationResponse, true, 512, JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR)['success'] |
||
37 | ) { |
||
38 | return true; |
||
39 | } |
||
40 | $errMsg = 'reCAPTCHA verification failed'; |
||
41 | throw new SecurityException('captcha', $exceptionType, $errMsg); |
||
42 | } |
||
44 |