reCaptcha and NMS integration solution

Showing 1-1 of 1 messages
reCaptcha and NMS integration solution girardot 6/28/08 4:05 PM
These are notes for how I added reCaptcha support to the NMS version
of (, a much better
version of the original

reCaptcha is a specific implementation of the general captcha idea and
more information about it can be found here:

I have the fully self contained, stand alone version of NMS installed, called the "compat" version on the sourceforge
page. This basically means the script has all the code it
needs are all in the one file, it has embedded any other modules it
might need to work directly in its own script. This makes it fully
self contained and doesn't need any additional modules to work making
installation simple.

My method installs the reCaptcha perl module in the system wide perl
installation and then calls that perl module from the

I took the example perl code from,
stripped out the HTML parts and stuck it in the script
following the conventions used in that script as best I could.

I am not a perl expert so I can't promise this is the best way to
accomplish this goal, but it does meet my needs just fine. I am all
for someone who really knows perl doing it the right way but people
have been asking around for a while and I haven't seen any other
solutions on the internet yet so I thought I would take a stab at it.

1. Install the reCaptcha perl module, at the time of writing this the
latest version was 0.92

Directly edit the script, add the two single lines and the
two following functions:

2. Line 1034 is blank, change it to:
use Captcha::reCAPTCHA;

3. Line 2094 is blank, change it to:
  $self->check_recaptcha or return;

4. Insert the following two functions into the script
starting at line 2104. Replace YOUR_PRIVATE_KEY_HERE with your actual
private key from the reCaptcha folks:

# START additions to support reCaptcha verification

=item check_recaptcha ( )

Uses the reCaptcha perl module to CHECK the user entered words.


sub check_recaptcha {
  my ($self) = @_;
  my $c = Captcha::reCAPTCHA->new;
  if ( $self->{Form}{recaptcha_response_field} ) {
    my $result = $c->check_answer(
    if ( $result->{is_valid} ) {
      return 1;
    else {
      return 0;
  else {
    return 0;

=item bad_recaptcha_error_page ()

Outputs the error page for a bad or missing reCaptcha user entry.


sub bad_recaptcha_error_page {
  my ($self) = @_;

  my $errhtml = <<END;
  The validation word response was missing or not correct.
  All test phrases are two words long so your entry should
  be two words as well. The presented words are generated
  automatically from a scanned book and are often hard to read.
  Please use the back button in your browser to return to the form
  and you will automatically have two new words. There is a small
  refresh icon next to the response field that will generate two
  new words if you can not read the two words presented.

  $self->error_page( 'Error: Incorrect or Missing Challenge Words',
$errhtml );

# END additions to support reCaptcha verification

5. Insert the following javascript in your form html to generate the
challenge words box from reCaptcha. I use a static HTML form to feed
my script so I use the javascript code from reCaptcha to
generate the challenge words. This javascript code can be found here since it might not
display properly below depending on where you are reading these notes.

<script type="text/javascript"

   <iframe src="<your_public_key>"
       height="300" width="500" frameborder="0"></iframe><br>
   <textarea name="recaptcha_challenge_field" rows="3" cols="40">
   <input type="hidden" name="recaptcha_response_field"

That should about do it really, those are all the changes I made to my
set up to get reCaptcha support in NMS

Best wishes,
Blake Girardot
bgirardot funnyatsymbol gmail com