<? DEW-CODE.COM  

Downloads

Assorted scripts  (1)
DewNewPHPLinks  (9)





Lost Password?
No account yet? Register

Dew-Code Newsfeed

Resources


 USdigitalcable.com

Dew-Code
Welcome, Guest
Please Login or Register.    Lost Password?
reCAPTCHA Functionality (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: reCAPTCHA Functionality
#910
gwilson (User)
Fresh Boarder
Posts: 15
graphgraph
User Offline Click here to see the profile of this user
Speak Spanish Like A Gringo
reCAPTCHA Functionality 2 Years, 8 Months ago Karma: 0  
Hi,

I would like the following comments to be read as a positive feedback, rather than an attempt to knock the hard work that has gone in to maintaining the dew-newphplinks code. As evidence that I am not here to simply "knock" and complain, I have attempted to put together some replacement code to allow reCAPTCHA (www.recaptcha.net) to be implemented as a replacement for the current CAPTCHA included with the recent version of dew-newphplinks.

Current CAPTCHA problems:

1. Unless I am mistaken, there are only 16 actual CAPTCHA images stored in the database, giving a spambot a 1 in 16 chance of guessing the correct code without even attempting to OCR the image.

2. Again, if I am not mistaken, the forms for add site and add review contain a checksum value (chksum) based on the capture. With only 16 images (and the code being publically available) it is possible for a spambot to store chksum values alongside the actual code (e.g. NCKDG checksum = 3ab1688b867b3c9c6998f9d00444a0cc) and there is no need for any additional work.

Solution:

1. reCAPTCHA - I suggest this as it provides a good level of security (I understand it has its own blocklists for known spam sources) and is growing 'familiarity' for web surfers as it is implemented on various sites and has plugins for various packages. I have successfully implemented it on multiple MediaWiki installations and a PHPBB3 forum.

Below I have included "my" code (actually taken from the reCAPTCHA example-captcha.php, so could be jazzed up a little). I understand that it is beyond the scope of dew-newphplinks to pre-package this, as it means it will not run "out of the box" without the admin getting a public/private keypair from the reCAPTCHA project. However, I do suggest that this code is developed and added as an official "plugin" option.

2. There must be an open source "draw on the fly" CAPTCHA package that could be added in place of the current CAPTCHA?

3. At least, at least hash the chksum value with some kind of 'salt' (perhaps current PHP Session ID, or even something static like the site name admins email address, which would at least make the MD5 chksum different on each installation across the web).

Cheers,
Graeme

******************************
*** reCAPTCHA installation ***
******************************
0. Make backup copies of add.php and review_add.php
1. download reCAPTCHA library and apply for reCAPTCHA keys for your domain (it is free)
2. copy recaptchalib.php to dir: 'include'
3. config.php - delete: $tb_captcha = 'phplinks_captcha';
3. MYSQL - delete table: 'phplinks_captcha'
4. add.php

require_once('recaptchalib.php';
// Get a key from http://recaptcha.net/api/getkey
$publickey = "";
$privatekey = "";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

5. add.php

find:

$cap = md5(strtoupper($_POST['capinput']));

replace with:

$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

6. add.php

find:

if ($_POST['chksum'] != $cap){
$error = 1;
$err.= 'The validation code you entered does not appear to be correct.<BR>';
}

replace with:

if ($resp->is_valid) {
# do nothing
}
else {
# set the error code so that we can display it
$err.= $resp->error . '<br />';
}

7. add.php

find:

$capquery = "SELECT * FROM $tb_captcha order by RAND() LIMIT 1";
$capsql = mysql_query("$capquery" or die("Invalid query: " . mysql_error());
$picrow = mysql_fetch_object($capsql);
$htmlsrc .= '<img align=top src="./include/captcha.php?x='.$picrow->ID.'"> ';
$htmlsrc .= '<input type=hidden name=chksum value="'.md5(strtoupper($picrow->checksum)).'">';
$htmlsrc .= '<input length=5 size=5 type=text name=capinput>';

replace with:

$htmlsrc .= recaptcha_get_html($publickey, $error);

8. review_add.php

add:

require_once('recaptchalib.php';
// Get a key from http://recaptcha.net/api/getkey
$publickey = "";
$privatekey = "";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

8. review_add.php

find:

$capinput = md5(strtoupper($_POST['capinput']));
$charcount = (strlen($_POST['chksum']) -1);
$cap = substr($_POST['chksum'], 0, $charcount);
if ($capinput != $cap){
$error = 1;
$caperr.= 'The validation code you entered does not appear to be correct.<BR>';
}

replace with:

$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($resp->is_valid) {
# do nothing
}
else {
# set the error code so that we can display it
$err.= $resp->error . '<br />';
}

8. review_add.php

find & delete:

$capquery = "SELECT * FROM $tb_captcha order by RAND() LIMIT 1";
$capsql = mysql_query("$capquery" or die("Invalid query: " . mysql_error());
$picrow = mysql_fetch_object($capsql);

find:

$html .= '<img align=top src="./include/captcha.php?x='.$picrow->ID.'"> ';
$html .= '<input type=hidden name=chksum value="'.md5(strtoupper($picrow->checksum)).$picrow->ID.'">';
$html .= '<input length=5 size=5 type=text name=capinput>';

replace with:

$htmlsrc .= recaptcha_get_html($publickey, $error);
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#911
Dewed (Admin)
Admin
Posts: 603
graph
User Online Now Click here to see the profile of this user
Dew-Code.com
Re:reCAPTCHA Functionality 2 Years, 8 Months ago Karma: 9  
Thanks for taking the time to contribute. Admittedly the current captcha system is primitive, but I was striving for something that didn't rely on the availability of graphic libraries. It's also pretty easy to add more combinations... which I should do, because as you point out 1:16 is insufficient.

If anyone is interested, the images are stored as jpeg images (with no compression) in a mysql blob.

on point #3... excellent point!

When free time and ambition allows I'll see if I can implement these ideas.

Thanks again
 
Report to moderator   Logged Logged  
 
Nothing to it but to Dew it !
Dew-Code.com
  The administrator has disabled public write access.
Go to top Post Reply
get the latest posts directly to your desktop
Outsource your projects to thousands of programmers at
ScriptLance.com
Newsflash
Interested in
advertising?

This space for rent!

Sign up for PayPal and start accepting credit card payments instantly.
Copyright Dew-Code 2008