| Hurray for CPAN module Authen::Captcha |
[28 Jan 2007|03:34pm] |

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