Konstrukt::Plugin::captcha - Put captchas in your forms easily.
<!-- the easy way --> <& captcha / &> <!-- defining your own settings that may differ from the defaults --> <& captcha type="text" template="/captcha/text.template" / &>
The captcha tag will usually be embedded in an existing <form
>. It will only generate (using a template) the question and two <input
> HTML-tags that will accept the answer and pass a hash of the correct answer to the server.
It's very easy to add a captcha-check to your plugins:
my $template = use_plugin 'template'; if ((use_plugin 'captcha')->check()) { #captcha solved! #your code... } else { #captcha not solved! #e.g. put error message and ask again: $self->add_node($template->node('error_message.template')); $self->add_node($template->node('template_with_input_form_and_captcha_tag.template')); }
This plugin will put a captcha on your website and allows you to check it easily.
There may be several implementation types, although currently only text captchas are implemented.
If the session management is activated, the user won't be asked to answer a captcha again, if (s)he already answered one correctly. This behaviour can be disabled in the setting captcha/ask_once
.
Also a user, which has logged on, won't be asked to enter a captcha. This behaviour can be disabled in the setting captcha/dont_ask_users
.
To create an captcha implementation, you must create plugin module Konstrukt::Plugin::captcha::your_type
.
This plugin needs to have a method display
, which will be called to display the captcha part of the input dialogue (i.e. the captcha question and the input fields for the answer (name="captcha_answer"
)and the hash checksum (name="captcha_hash"
)).
This will be done like every (simple) plugin does via print
or $self-
add_node()> (see "add_node" in Konstrukt::Plugin).
You might want to take an existing implementation as a template.
Parameters:
You may control the behaviour of this plugin with some settings. Defaults:
captcha/type text captcha/template_path /templates/captcha/ captcha/ask_once 1 captcha/dont_ask_users 1
Inititalization of this class
Checks if the user answer matches the captcha question. This is done by hashing the user answer and comparing it to the hashed correct answer.
Returns true, if the answer is correct.
Parameters: none
Installs the templates.
Parameters:
none
Default (and only) action for this plugin. Will display the captcha according to the attributes set in the <& captcha / &
> tag.
The attributes are optional. Their value defaults are defined in the settings.
Tag attributes:
captcha/type
).captcha/template_path
$type
.template". The variables answer
and hash
will be passed to your template.Parameters:
This is a demo/debug action, which allows you to test your captcha.
Just put this code on a web page:
<form action="" method="post"> <input type="hidden" name="captcha_action" value="solve" /> <& captcha / &> <input type="submit" value="Check" /> </form>
Okay, this is some kind of a dirty hack, but it should work for test purposed.
Copyright 2006 Thomas Wittek (mail at gedankenkonstrukt dot de). All rights reserved.
This document is free software. It is distributed under the same terms as Perl itself.