Authen-PluggableCaptcha
view release on metacpan or search on metacpan
samples/mod_perl.txt view on Meta::CPAN
$captcha= Authen::PluggableCaptcha->new(
type=> 'new' ,
site_secret=> $FindMeOn::Config::site_secret ,
seed=> $seed ,
);
$captcha_key= $captcha->get_publickey() or die "Error";
$pageObject->PageUser->set_session_stored("captcha_publickey__${sectionName}",$captcha_key);
$captcha= Authen::PluggableCaptcha->new(
type=> 'existing' ,
site_secret=> $FindMeOn::Config::site_secret ,
seed=> $seed ,
publickey=> $captcha_key,
);
}
$pageObject->{'CaptchaInstance'}= $captcha;
}
# a page that displays / verifies captchas just calls:
&CAPTCHA_init( $self , 'registration', 1 );
# to show a text captcha, we can render this directly into a Petal document
%PetalPersonalizedHash= (
'Captcha'=> {
instructions=> undef,
user_prompt=> $self->{'CaptchaInstance'}->render(
challenge_class=> 'Authen::PluggableCaptcha::Challenge::DoMath',
render_class=>'Authen::PluggableCaptcha:::Render::Text::HTML'
),
},
);
# validate?
if (
!$self->{'CaptchaInstance'}->validate_response(
challenge_class=> 'Authen::PluggableCaptcha::Challenge::DoMath',
user_response=> $self->{'Form'}->get_validated('captcha_response'),
)
) {
$self->{'Form'}->set_error('captcha_response','That answer is not correct, please try again');
return $self->FORM_print();
}
else {
# we're valid!
}
# so you want to display an image?
# print the image on one page:
my $captcha_embed= "<img src="/path/to/captcha/handler?section=registration" />";
# then set a sub to generate it on that url mapping
# in this example, the captcha generator is in a central location -- /service/captcha/
# so we supply the section name as a query arg. if the captcha generator were locked into a page, then you could just hardcode the section name
sub render_image {
my ( $self )= @_ ;
my $sectionName= $self->PageUser->ApacheRequest->param('section');
#initialize the captcha
&FindMeOn::Functions::Misc::CAPTCHA_init( $self , $sectionName );
$self->PageUser->ApacheRequest->content_type('image/jpeg');
$self->{'__BODY'}= $self->{'CaptchaInstance'}->render(
challenge_class=> 'Authen::PluggableCaptcha::Challenge::TypeString',
render_class=>'Authen::PluggableCaptcha::Render::Image::Imager' ,
font_filename=> '/usr/X11R6/lib/X11/fonts/TTF/VeraMoIt.ttf',
format=>'jpeg'
);
return;
}
( run in 1.455 second using v1.01-cache-2.11-cpan-437f7b0c052 )