bazbax (foobarbazbax) wrote,

Hurray for CPAN module Authen::Captcha

I've never done any captcha before. I've been working on implementing an online payment system that checks the CSC. The trouble is that if I allow the user to retry, which is necessary for good usability, they can easily write a script to try 1000 times and exhaust all possibilities. I've decided that this is a good use of captcha. After a couple of failures, a captcha shows up.

Look how easy it is to generate 5 character captchas in Perl. This code generated the captcha at the top of this post.


use strict;
use warnings;

use Authen::Captcha;
use IO::Prompt;

my $captcha = Authen::Captcha->new(
        data_folder   => '/tmp/Authen_Captcha',
        output_folder => '~/public_html/',

my $md5sum = $captcha->generate_code(5);
my $code = prompt "What's $md5sum.png say: ";
my $result = $captcha->check_code( $code, $md5sum );

if ( $result == 1 ) {
        print "You entered the correct code\n";
} else {
        print "Failure\n";
  • Post a new comment


    default userpic