Has anyone successfully implemented reCAPTCHA 2.0 on the login page (or the sign-up or password reset pages?) I was hoping to add it to all of them.
Getting it to display was simple enough, but I got totally lost/stuck editing the index.php which seems to control the POST submissions. I couldn't combine the code needed for the recaptcha submission with the existing login/logout/wrong password code that already exists. I'd either manage to stop it allowing any logins, or totally ignore the captcha completely!
If anyone else is doing this or has done this, I'd love to see your working.
Thanks,
TNL
Implement reCAPTCHA
-
- Posts: 13
- Joined: 2015-12-16 12:54
Re: Implement reCAPTCHA
Hi,
I follow the tutorial
http://stackoverflow.com/questions/2727 ... r-side-php
For the server side, you have to modify the incCommon.php file:
function logInMember(){
$redir = 'index.php';
if($_POST['signIn'] != ''){
//DEBUT AJOUT POUR LE CAPTCHA
if(isset($_POST['signIn']) && !empty($_POST['signIn'])){
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){
//your site secret key
$secret = 'YOURSECRETCODE';
//get verify response data
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/si ... e='.$_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if($responseData->success){
//FIN AJOUT POUR LE CAPTCHA
if($_POST['username'] != '' && $_POST['password'] != ''){
$username = makeSafe(strtolower($_POST['username']));
$password = md5($_POST['password']);
if(sqlValue("select count(1) from membership_users where lcase(memberID)='$username' and passMD5='$password' and isApproved=1 and isBanned=0")==1){
$_SESSION['memberID']=$username;
$_SESSION['memberGroupID']=sqlValue("select groupID from membership_users where lcase(memberID)='$username'");
if($_POST['rememberMe']==1){
@setcookie('Rela-TIC_rememberMe', md5($username.$password), time()+86400*30);
}else{
@setcookie('Rela-TIC_rememberMe', '', time()-86400*30);
}
// hook: login_ok
if(function_exists('login_ok')){
$args=array();
if(!$redir=login_ok(getMemberInfo(), $args)){
$redir='index.php';
}
}
redirect($redir);
exit;
}
}
// hook: login_failed
if(function_exists('login_failed')){
$args=array();
login_failed(array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'IP' => $_SERVER['REMOTE_ADDR']
), $args);
}
//DEBUT AJOUT POUR LE CAPTCHA
$succMsg = 'Your contact request have submitted successfully.';
}else{
$errMsg = 'Robot verification failed, please try again.';
}
}else{
$errMsg = 'Please click on the reCAPTCHA box.';
}
}
//FIN AJOUT POUR LE CAPTCHA
I follow the tutorial
http://stackoverflow.com/questions/2727 ... r-side-php
For the server side, you have to modify the incCommon.php file:
function logInMember(){
$redir = 'index.php';
if($_POST['signIn'] != ''){
//DEBUT AJOUT POUR LE CAPTCHA
if(isset($_POST['signIn']) && !empty($_POST['signIn'])){
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){
//your site secret key
$secret = 'YOURSECRETCODE';
//get verify response data
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/si ... e='.$_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if($responseData->success){
//FIN AJOUT POUR LE CAPTCHA
if($_POST['username'] != '' && $_POST['password'] != ''){
$username = makeSafe(strtolower($_POST['username']));
$password = md5($_POST['password']);
if(sqlValue("select count(1) from membership_users where lcase(memberID)='$username' and passMD5='$password' and isApproved=1 and isBanned=0")==1){
$_SESSION['memberID']=$username;
$_SESSION['memberGroupID']=sqlValue("select groupID from membership_users where lcase(memberID)='$username'");
if($_POST['rememberMe']==1){
@setcookie('Rela-TIC_rememberMe', md5($username.$password), time()+86400*30);
}else{
@setcookie('Rela-TIC_rememberMe', '', time()-86400*30);
}
// hook: login_ok
if(function_exists('login_ok')){
$args=array();
if(!$redir=login_ok(getMemberInfo(), $args)){
$redir='index.php';
}
}
redirect($redir);
exit;
}
}
// hook: login_failed
if(function_exists('login_failed')){
$args=array();
login_failed(array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'IP' => $_SERVER['REMOTE_ADDR']
), $args);
}
//DEBUT AJOUT POUR LE CAPTCHA
$succMsg = 'Your contact request have submitted successfully.';
}else{
$errMsg = 'Robot verification failed, please try again.';
}
}else{
$errMsg = 'Please click on the reCAPTCHA box.';
}
}
//FIN AJOUT POUR LE CAPTCHA