Catalyst::TraitFor::Controller::CAPTCHA - authenticate human by create and validate captcha
version 1.2
In your controller
package MyApp::Controller::MyController; use Moose; use namespace::autoclean; BEGIN { extends 'Catalyst::Controller' } with 'Catalyst::TraitFor::Controller::CAPTCHA'; sub captcha_image : Local :Args(0) { my ( $self, $c ) = @_; $c->forward('generate_captcha'); } #Now <img src="/captcha_image" /> will have captcha and #<input name="captcha_text" type="text"> will prompt user to enter captcha text #and this should be embed into your form that needs to be validated. sub form_post : Local { my ($self,$c) = @_; my $posted_string = $c->req->body_params('captcha_text'); if ( $c->forward('validate_captcha',[$posted_string]) ) { #Allowed }else { #Not Allowed } } 1;
This Catalyst::Controller role provides Private methods that deal with the generation and validation of captcha.
Private
In MyApp.pm (or equivalent in config file):
__PACKAGE__->config->{captcha} = { session_name => 'captcha_string', #Refer GD::SecurityImage for additonal configuration gd_config => { width => 100, height => 50, lines => 5, gd_font => 'giant', }, create => [qw/normal rect/], particle => [10], out => {force => 'jpeg'} };
This controller's private methods will create and validate captcha.This module is based/altered from Catalyst::Plugin::Captcha because that shouldn't be a Catalyst::Plugin.Now it is a base controller like Catalyst::TraitFor::Controller::reCAPTCHA.It uses GD::SecurityImage and requires a session plugins like Catalyst::Plugin::Session.
This will create and respond the captcha.
$c->forward('generate_captcha');
This will validate the given string against the Captcha image that has been generated earlier.
if ( $c->forward('validate_captcha',[$posted_string]) ) { #do something based on the CAPTCHA passing }
https://github.com/Virendrabaskar/Catalyst-TraitFor-Controller-CAPTCHA
Catalyst::TraitFor::Controller::reCAPTCHA
Catalyst::Controller
Catalyst
GD::SecurityImage
This module is almost copied from Diego Kuperman Catalyst::Plugin::Captcha.
Baskar Nallathambi <baskarmusiri@gmail.com>,<baskar@exceleron.com>
This is free module.You can do anything to this module under the same terms as the Perl 5 programming language system itself.
To install Catalyst::TraitFor::Controller::CAPTCHA, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::TraitFor::Controller::CAPTCHA
CPAN shell
perl -MCPAN -e shell install Catalyst::TraitFor::Controller::CAPTCHA
For more information on module installation, please visit the detailed CPAN module installation guide.