CAPTCHA Generation in perl using Authen:: Captcha
I have already given algorithm and the existing code to generate the verification image (SAPTCHA) for perl, implemented with the assistance of the library Image:: Magick (provides an interface between perl and most imagemagick). Now I want to talk about working with the library Authen:: Captcha, since the interaction with it easier, although loss of flexibility in setting the generated image. By the way, there is flexibility in the library GD:: SecurityImage, but it otstutstvuet simple mechanism for evaluation of user input (this deficiency should be deprived of GD:: SecurityImage:: AC - "fusion" Authen:: Captcha and GD:: SecurityImage, which I also definitely try and tell you about the results).
Perl code to generate the CAPTCHA image
#! / Usr / bin / perl use Authen:: Captcha; use Digest:: MD5 qw (md5_hex); my $ cap_data_folder = 'tmp / captcha'; # There will be a text file with code CAPTCHA my $ cap_out_folder = 'tmp / outputcaptcha'; # Here are CAPTCHA image verification my $ cap_length = 4 # How many characters will be CAPTCHA my $ captcha = Authen:: Captcha-> new (data_folder => $ cap_data_folder, output_folder => $ cap_out_folder,); my $ md5sum = $ captcha-> generate_code ($ cap_length);
This code will create a set of characters will generate an image based on it and return md5 hash for him. Our next task - to verify the user entered code sootvtetstvie sgenerirovannomuyu.
Perl code to check the value entered CAPTCHA
To check the value entered by the user to compute the captcha md5 hash (which is used for this library Digest:: MD5).
my $ md5sum = md5_hex ($ cap_input_value); # md5 hash Vychslyaem for user input my $ result = $ captcha-> check_code ($ cap_input_value, $ md5sum); # We return a hash to verify
Scan results are given in the documentation for Authen:: Captcha, I also duplicate them below:
1: Passed
0: Code not checked (file error)
-1: Failed: code expired
-2: Failed: invalid code (not in database)
-3: Failed: invalid code (code does not match crypt)
Thus, it is enough simply to make the conditions of operation, depending on test results. Easier than
More on similar topics:
Filed under: Internet , Coding |
Tags: captcha , How-to , perl , programming |
10 comments 

Can't locate Authen / Captcha.pm in @ INC (@ INC contains ....
Modules installed but the problem persists
That set - it was good. But if the problem persists - would suggest that the installation location is not indicated in @ INC.
Need to check where the unit (especially if you installed is not native to the system package manager or from the Rutaceae cpan) and add the path to @ INC.
Launched by the way on Nix, a native system for Perl
And what's the point in these captures, if any OCR-service type can pass them. You can even check their CAPTCHAs - there you can download them for free test
There, as I understand, recognize people. A CAPTCHA - from bots.
Well, after all bots send the captcha on the recognition of people! And the boat is protected.
By the way, there can test the CAPTCHA on your stability. Hagruzhaete it there and see how people recognize her.
That's right. I mean, what do captcha from human sense, but once people recognize these services - do something stupid captcha discuss in this way. People and should recognize her.
Next question of economic feasibility, as people recognize not free. Thus CAPTCHA on sites like my completely justified - it cuts off the bots, and recognition for a man hardly anyone would pay.
You know, I could well pay 30 rubles for me to recognize in 1000 captures. It's 1000 messages, or register an account or soaps for a ridiculous amount.
What this proves or disproves in light of the above? If you find acceptable expected dividends from such investments - why not?