Hi, I'm Chris Moyer's Blog.

reCAPTCHA -- Fight Spam, Read Books

In a startling development (to me), my small blog started getting spammed like crazy. Out of 100+ posts, a handful were legitimate. After going through the process of manually deleting them all, I decided to invest a bit of time in a CAPTCHA system for my blosxom blogging software. Having seen the reCAPTCHA interface on several sites, and read about it before, I decided to start there.

Basically, reCAPTCHA provides some incredibly simple APIs to add a CAPTCHA to your site. The neat part about it, though, is that the images presented to the user are actually difficult to scan words from real-life books. The results of people submitting these CAPTCHAs are combined to improve the digitization of hard-copy archives. The learn more page on the reCAPTCHA site has a more detailed explanation.

Implementation

Step 1 – Sign Up, Get Keys

Here

Step 2 – Add the the interface to the front end

	<script	type="text/javascript"

		src="http://api.recaptcha.net/challenge?k=$MYKEY">

	</script>

This javascript (and iframe) API takes several parameters, allowing you to customize the look and feel of the interface.

Step 3 – Validate the submitted reCAPTCHA

As bloxsom is written in perl, I went with the CPAN module Captcha::reCAPTCHA.

	use Captcha::reCAPTCHA;

	my $rec = Captcha::reCAPTCHA->new;

my $rec_res = $rec→check_answer(‘6LdWHQEAAAAAAORoD7pXt_BAHRdsZ2GPjmcFdWWi', $ENV{'REMOTE_ADDR'},
param(‘recaptcha_challenge_field'), param(‘recaptcha_response_field'));

// [snip some lines]

if (!$good || !$rec_res→{is_valid}) {
$comment_response = “Some required fields were missing.”;
if (!$rec_res→{is_valid}) {
$comment_response = ‘Please verify that you are human, with the reCAPTCHA!';
}
}

Obviously, not the most elegant code, but it was an incredibly simple process… and my blog has been spam free for 3 weeks!



Back to Blog Home »