Author Topic: [Mod] Captcha can mathematics  (Read 69022 times)

0 Members and 1 Guest are viewing this topic.

Rembrandt

  • Guest
[Mod] Captcha can mathematics
« on: November 01, 2010, 03:09:29 PM »
Hi!
 
 With this Modifikation can captcha mathematics, for a little bit more spammbot protection.

Captcha mathematics for Register, - Comments, and Postcards.
 
 Demo

1.) search in includes/captcha_utils.php:
function captcha_get_code() {
  global 
$captcha_path$captcha_chars$captcha_wordfile$captcha_length;

replace:

//###################### captcha mathematics start #######################
function calculation(){
  global 
$site_sess;
  
$math range(0,9);
  
shuffle($math);
  
  
$code "$math[0]+$math[1]+$math[2]";
  
$sum $math[0]+$math[1]+$math[2];
  
$site_sess->set_session_var('result'$sum);
    
  return 
$code;
}

function 
captcha_validate_sum($result) {
  global 
$site_sess$captcha_enable$user_info;
  
  if (!
$captcha_enable || $user_info['user_level'] == ADMIN) {
    return 
true;
  }

  
$sess_sum =  trim($site_sess->get_session_var('result'));

  
$valid_result $sess_sum != '' && $sess_sum == $result;

  
$site_sess->drop_session_var('result');

  return 
$valid_result;
}
//###################### captcha mathematics end #########################
function captcha_get_code() {
  global 
$captcha_path$captcha_chars$captcha_wordfile$captcha_length,$captcha_calculation;
//###################### captcha mathematics start #######################
  
if($captcha_calculation){
    return 
calculation();
  }
//###################### captcha mathematics end #########################


2.) search in root/global.php:
$captcha_ttf                 1;
insert below:
$captcha_calculation         1// "0"  turn off captcha mathematics

3.) search in your Template/style.css:
Code: [Select]
.input{
  font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif;
  color: #0f5475;
  font-size: 11px;
  width: 230px;
}
insert below:
Code: [Select]
.input_res{
  font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif;
  color: #0f5475;
  font-size: 11px;
  width: 30px;
}

4.) search in lang/deutsch/main.php:

$lang
['captcha_required'] = 'Das Feld mit dem Bestätigungs-Code muss ausgefüllt werden.';

insert below:

$lang
['captcha_result'] = "Ihr Ergebnis stimmt nicht, bitte versuchen Sie es noch einmal !";
$lang['captcha_desc_result'] = "Bitte tragen Sie die Rechnung aus dem Bild in das Textfeld darunter ein, und schreiben das Ergebnis rechts davon hinein.<br>Wenn Sie Probleme haben den Code zu erkennen, klicken Sie auf das Bild um ein neues zu erhalten.";
     
4.1.) search in lang/english/main.php:
$lang['captcha_required'] = 'Please enter the verification code.';
insert below:

$lang
['captcha_result'] = "Your result is wrong, please try again !";
$lang['captcha_desc_result'] = "Please enter the code from the image into the text field below, and write the result right inside of it.<br>If you have problems identifying the image, click on it to get a new one..";



5.) For Register: search in root/register.php:

$captcha 
= (isset($_POST['captcha'])) ? un_htmlspecialchars(trim($_POST['captcha'])) : "";

insert below:

//###################### captcha mathematics start #######################
     
$result = (isset($_POST['result'])) ? intval(trim($_POST['result'])):"";
//###################### captcha mathematics end #######################

search:

if ($captcha_enable_registration && !captcha_validate($captcha)) {
      
$msg .= (($msg != "") ? "<br />" "").$lang['captcha_required'];
      
$error 1;
    }

insert below:

//###################### captcha mathematics start #######################
  
if ($captcha_enable_registration && $captcha_calculation && !captcha_validate_sum($result)) {
      
$msg .= (($msg != "") ? "<br />" "").$lang['captcha_result'];
      
$error 1;
    }
//###################### captcha mathematics end #######################    

search:

      
"lang_captcha_desc" => $lang['captcha_desc'],

and replace:

//###################### captcha mathematics start #######################  
      
"captcha_calculation" => (bool)$captcha_calculation,
      
"lang_captcha_desc" => ($captcha_calculation) ? $lang['captcha_desc_result'] : $lang['captcha_desc'],
//###################### captcha mathematics end #########################      


5.1) search in your templatet/register_form.html:
Code: [Select]
<input type="text" name="captcha" size="30" value="" class="captchainput" id="captcha_input" />
and replace:
Code: [Select]
<input type="text" name="captcha" size="30" value="" class="captchainput" id="captcha_input" />{if captcha_calculation} = <input class="input_res" name="result" type="text" >{endif captcha_calculation}

6.) For Comments: search in root/details.php:

$captcha 
= (isset($_POST['captcha'])) ? un_htmlspecialchars(trim($_POST['captcha'])) : "";

insert below:

//###################### captcha mathematics start #######################
     
$result = (isset($_POST['result'])) ? intval(trim($_POST['result'])):"";
//###################### captcha mathematics end #######################     

search:

if ($captcha_enable_comments && !captcha_validate($captcha)) {
      
$msg .= (($msg != "") ? "<br />" "").$lang['captcha_required'];
      
$error 1;
    }

insert below:

//###################### captcha mathematics start #######################
  
if ($captcha_enable_comments && $captcha_calculation && !captcha_validate_sum($result)) {
      
$msg .= (($msg != "") ? "<br />" "").$lang['captcha_result'];
      
$error 1;
    }
//###################### captcha mathematics end #######################    

search:

      
"lang_captcha_desc" => $lang['captcha_desc'],

and replace:

//###################### captcha mathematics start #######################  
      
"captcha_calculation" => (bool)$captcha_calculation,
      
"lang_captcha_desc" => ($captcha_calculation) ? $lang['captcha_desc_result'] : $lang['captcha_desc'],
//###################### captcha mathematics end #########################      


6.1) search in your templatet/comment_form.html:
Code: [Select]
<input type="text" name="captcha" size="30" value="" class="captchainput" id="captcha_input" />
and replace:
Code: [Select]
<input type="text" name="captcha" size="30" value="" class="captchainput" id="captcha_input" />{if captcha_calculation} = <input class="input_res" name="result" type="text" >{endif captcha_calculation}</td>

7.) For Postcards: search in root/postcards.php:

$captcha 
= (isset($_POST['captcha'])) ? un_htmlspecialchars(trim($_POST['captcha'])) : "";

insert below:

//###################### captcha mathematics start #######################
     
$result = (isset($_POST['result'])) ? intval(trim($_POST['result'])):"";
//###################### captcha mathematics end #######################     

search:

 
if ($captcha_enable_postcards && !captcha_validate($captcha)) {
      
$msg .= (($msg != "") ? "<br />" "").$lang['captcha_required'];
      
$action "previewcard";
      
$main_template "postcard_preview";
  }    

insert above:

//###################### captcha mathematics start #######################
  
if ($captcha_enable_postcards && $captcha_calculation && !captcha_validate_sum($result)) {
      
$msg .= (($msg != "") ? "<br />" "").$lang['captcha_result'];
      
$action "previewcard";
      
$main_template "postcard_preview";;
    }
//###################### captcha mathematics end #######################    

search:

      
"lang_captcha_desc" => $lang['captcha_desc'],

and replace:

//###################### captcha mathematics start #######################  
      
"captcha_calculation" => (bool)$captcha_calculation,
      
"lang_captcha_desc" => ($captcha_calculation) ? $lang['captcha_desc_result'] : $lang['captcha_desc'],
//###################### captcha mathematics end #########################      


7.1) search in your template/postcard_preview.html:
Code: [Select]
<input type="text" name="captcha" size="30" value="" class="captchainput" id="captcha_input" />
and replace:
Code: [Select]
<input type="text" name="captcha" size="30" value="" class="captchainput" id="captcha_input" />{if captcha_calculation} = <input class="input_res" name="result" type="text" >{endif captcha_calculation}</td>


mfg Andi
« Last Edit: October 02, 2013, 07:16:52 PM by Rembrandt »

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: [Mod] Chaptcha can mathematics
« Reply #1 on: November 01, 2010, 07:27:20 PM »
Danke Andi ...

... unter 4.1 ... insert below ... musst du den BB-Code noch richtig stellen .... ;)

Gruss mawenzi
Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...

Rembrandt

  • Guest
Re: [Mod] Chaptcha can mathematics
« Reply #2 on: November 01, 2010, 07:35:18 PM »
Danke @mawenzi !
 x mal angeschaut und doch wieder was übersehn.  :)

mfg Andi

Offline Jan-Lukas

  • Addicted member
  • ******
  • Posts: 1.289
    • View Profile
    • Discover the New World of Kindersurprise
Re: [Mod] Chaptcha can mathematics
« Reply #3 on: November 01, 2010, 08:44:25 PM »
toller Mod, mir persönlich aber etwas zu undeutlich  :wink:
aber soll ja sicher sein :thumbup:

Harald
Danke Harald




Rembrandt

  • Guest
Re: [Mod] Chaptcha can mathematics
« Reply #4 on: November 01, 2010, 08:55:20 PM »
toller Mod, mir persönlich aber etwas zu undeutlich  :wink:
aber soll ja sicher sein :thumbup:
meinst du jetzt die lesbarkeit des codes, das sollte eigentlich nicht so sein, einen spambot ist es egal wie undeutlich der code auch ist,
 aber die Usability (Benutzerfreundlichkeit) sollte nicht darunter leiden.
du könntest den code ja mit diesem [tut] http://www.4homepages.de/forum/index.php?topic=21028.msg114321#msg114321
etwas entschärfen.

mfg Andi

Offline Jan-Lukas

  • Addicted member
  • ******
  • Posts: 1.289
    • View Profile
    • Discover the New World of Kindersurprise
Re: [Mod] Chaptcha can mathematics
« Reply #5 on: November 01, 2010, 09:13:54 PM »
ja, einige Zahlen sind etwas undeutlich, und bin auch mit dem + und x auf dem Kriegsfuß (in der Demo)
Aber meinen Code habe ich mit dem von Detlev entschärft  :wink:
Aber bei uns dürfen sowieso nur registrierte schreiben, aber wird selten genutzt  :o

Aber wie gesagt, tolle Erweiterung
Danke Harald




Rembrandt

  • Guest
Re: [Mod] Chaptcha can mathematics
« Reply #6 on: November 01, 2010, 09:35:30 PM »
ja, einige Zahlen sind etwas undeutlich, und bin auch mit dem + und x auf dem Kriegsfuß (in der Demo)
....
ja das sind alles '+' und keine '*'  :mrgreen:
ich werde wohl auch @mawenzis setting übernehmen..

mfg Andi

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Chaptcha can mathematics
« Reply #7 on: November 02, 2010, 12:27:00 AM »
Very good idea! Thanks for sharing.

How about add subtraction (-) and multiplication (*)? ;)
function getMath()
{
  
$operators = array("+""-""*");
  
$count count($operators) - 1;
  do
  {
    
$num mt_rand(24); //number of numbers in final formula
    
$formula "";
    while(
$num--)
      
$formula .= ($formula !== "" $operators[mt_rand(0$count)] : "") . mt_rand(09);

  
	
$func create_function("""return (" $formula ");" );
    
$compute = (int)$func();
  }
  while(
$compute || $compute 50); //we need a simple formula, so loop until the computed number is between 1 and 50
  
return array($formula$compute);
}


Also, the installation of the mod could be simplified to at least in half, if instead of calling captcha_validate_sum() function from "main" files it would be called within captcha_validate() function. With this method no additional changes required in details.php, register.php, etc
You can see what I mean in reCAPTCHA mod.
« Last Edit: November 02, 2010, 12:46:49 AM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Rembrandt

  • Guest
Re: [Mod] Chaptcha can mathematics
« Reply #8 on: November 02, 2010, 05:25:41 AM »
Hi!

...How about add subtraction (-) and multiplication (*)? ;)
Thank you for the function, but i think this is no way to spambot protection.
 for spambots is no relevants he can all math, only the "usability" is gone.

Quote
... if instead of calling captcha_validate_sum() function from "main" files it would be called within captcha_validate() function. ...
I have to think about it...  8O

mfg Andi

Offline kai

  • Administrator
  • Addicted member
  • *****
  • Posts: 1.421
    • View Profile
    • 4images - Image Gallery Management System
Re: [Mod] Chaptcha can mathematics
« Reply #9 on: November 02, 2010, 07:42:54 PM »
rated 5 stars
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline taru

  • Pre-Newbie
  • Posts: 5
    • View Profile
    • Фото Петербурга. St.-Petersburg photos
Re: [Mod] Captcha can mathematics
« Reply #10 on: September 28, 2012, 03:29:27 PM »
Super!   :thumbup:
Наконец-то избавился от роботов-спамеров!!!

Offline tramfahrer

  • Full Member
  • ***
  • Posts: 112
    • View Profile
    • Straßenbahn-, Bus- und Eisenbahnbilder
Re: [Mod] Captcha can mathematics
« Reply #11 on: November 18, 2012, 06:40:28 PM »
Danke Danke Danke :-)

hab es bei mir gleich eingefügt, ich hoffe mal, das jetzt bei mir der Kommentarspam ein Ende hat. Recaptcha hat ja kläglich versagt, und ich hatte innerhalb von 2 Tagen mehrere hunderte Spamkommentare, obwohl Kommentare nur für registrierte User möglich ist.

Rembrandt

  • Guest
Re: [Mod] Captcha can mathematics
« Reply #12 on: November 18, 2012, 06:52:01 PM »
na Bitte :)
 da bin ich auch gespannt, vielleicht kannst du darüber Berichten ob es geklappt hat.

mfg Andi

Offline kubiczek

  • Full Member
  • ***
  • Posts: 211
    • View Profile
    • Gross Peterwitz
Re: [Mod] Captcha can mathematics
« Reply #13 on: November 18, 2012, 09:55:09 PM »
Ich habe es seit einigen Monaten,  bis jetzt ist kein einziger eintrag erfolgt.

Die Akzeptanz der User ist auch vorhanden,

Danke Rembrandt :D

Rembrandt

  • Guest
Re: [Mod] Captcha can mathematics
« Reply #14 on: November 19, 2012, 05:26:36 AM »
Hi!
Ich habe es seit einigen Monaten,  bis jetzt ist kein einziger eintrag erfolgt.
...
mit dem hätte ich nicht gerechnet, Danke fürs Feedback.

mfg Andi