bazbax ([info]foobarbazbax) wrote,
@ 2007-01-28 15:34:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
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.

#!/usr/bin/perl

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";
}



(2 comments) - (Post a new comment)


[info]n0xi0uzz
2007-10-12 08:07 am UTC (link)
Does it delete image after checking?

(Reply to this) (Thread)


[info]foobarbazbax
2007-10-12 05:26 pm UTC (link)
I'm pretty sure it is deleted when the program exits, but you'll probably want to double check that.

(Reply to this) (Parent)


(2 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…