Auth Form wiht Google reCAPTCHA (#87)

* reCaptcha config

* config reCaptcha

* check reCAPTCHA

* add reCAPTCHA to form login

* config attributes for reCAPTCHA

* Function to verify request with reCAPTCHA

* doc reCaptcha
This commit is contained in:
Genaro Contreras Gutierrez
2020-02-19 14:04:20 -08:00
committed by GitHub
parent 8f4ced96f9
commit cbdc0dacd6
5 changed files with 100 additions and 21 deletions

View File

@@ -574,6 +574,20 @@ class Config {
$this->default->search['time_limit'] = array(
'desc'=>'Maximum time to allow unlimited size_limit searches to the ldap server',
'default'=>120);
/* reCAPTCHA Login */
$this->default->session['reCAPTCHA-enable'] = array(
'desc'=>'Status reCAPTCHA (true | false)',
'default'=>false);
$this->default->session['reCAPTCHA-key-site'] = array(
'desc'=>'Site Key',
'default'=>"<put-here-key-site>");
$this->default->session['reCAPTCHA-key-server'] = array(
'desc'=>'Server key',
'default'=>"<put-here-key-server>");
}
/**

View File

@@ -3217,4 +3217,30 @@ function isAjaxEnabled() {
else
return false;
}
/**
* Check if user is a robot with reCAPTCHA
**/
function IsRobot($gResponse){
$isRobot = true;
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => $_SESSION[APPCONFIG]->getValue('session','reCAPTCHA-key-server'),
'response' => $gResponse
);
$options = array(
'http' => array (
'method' => 'POST','header' =>
'Content-Type: application/x-www-form-urlencoded',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success = json_decode($verify);
if ($captcha_success->success) {
$isRobot = false;
}
return $isRobot;
}
?>