Added Cloudflare Turnstile as alternative to Google reCAPTCHA

Added the option to select Cloudflare's Turnstile instead of Google's reCAPTCHA for the login page due to it's less intrusive usage and better accessibility options.
This commit is contained in:
KuJoe 2024-05-20 20:19:32 -04:00
commit 46be29978d
7 changed files with 74 additions and 27 deletions

View file

@ -3561,12 +3561,9 @@ function remove_html_comments($content)
// Google recaptcha
function isCaptcha($reCaptchaResponse)
{
if (config('google.reCaptcha') != 'true') {
return true;
}
$url = "https://www.google.com/recaptcha/api/siteverify";
$options = array(
"secret" => config("google.reCaptcha.private"),
"secret" => config("login.protect.private"),
"response" => $reCaptchaResponse,
"remoteip" => $_SERVER['REMOTE_ADDR'],
);
@ -3581,6 +3578,35 @@ function isCaptcha($reCaptchaResponse)
return ($json['success']);
}
// Cloudflare Turnstile
function isTurnstile($turnstileResponse)
{
$public = config("login.protect.public");
$private = config("login.protect.private");
$ip = $_SERVER['REMOTE_ADDR'];
$url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
$data = array('secret' => $private, 'response' => $turnstileResponse, 'remoteip' => $ip);
$options = array(
'http' => array(
'method' => 'POST',
'content' => http_build_query($data))
);
$stream = stream_context_create($options);
$fileContent = file_get_contents($url, false, $stream);
if ($fileContent === false) {
return false;
}
$json = json_decode($fileContent, true);
if ($json == false) {
return false;
}
return ($json['success']);
}
// Get video ID
function get_video_id($url)
{