[pmwiki-users] Experimental captcha recipe

marc gmane at auxbuss.com
Tue May 8 04:01:42 CDT 2007


Patrick R. Michaud said...
> For those who are curious, I'm playing with an experimental
> captcha recipe at 
> 
>     http://www.pmwiki.org/wiki/Test/Captcha
> 
> The recipe adds an (:input captcha:) form type, as well
> as a {$Captcha} page variable.  These can be added to existing
> edit forms or (coming soon) mail form recipes to help filter
> bots.
> 
> For sites that don't have PHP image libraries available, the
> {$Captcha} markup displays the challenge value as plain text
> instead of an image.  It's also configurable, which means that
> it will be possible to plug in other obscuration methods
> if plain text or the captcha image generator I'm using aren't
> sophisticated enough.
> 
> Comments, questions welcomed.

I started a captcha recipe a few weeks ago, but it got sidelined due to 
other things - although they are quite cool things :-)

I know folk aren't enamoured by object orientation around here - I can't 
help it being a Java and Ruby dude - but I felt that a captcha recipe is 
an ideal candidate for using the strategy pattern.

Put simply, this would mean that the captcha algorithms are each 
encapsulated in their own class. The appropriate class is then 
determined at runtime, via, say, a parameter in the markup.[1]

In this way, the recipe can easily be extended with the admin's 
preferred captcha algorithms, without the recipe needing to be updated - 
nor would it need to include each and every available algorithm.[2]

It would also be easy for folk to post new algos to the list, or on the 
recipe page, and folk could use them without disturbing the recipe. You 
could even have different captcha algos per page, group, etc.

You could do this procedurally, of course, but it would be a rather ugly 
hack, imo. (Ducks and runs at expressing a preference for OO over 
procedural methods.)

Just my 2c.

-- 
Cheers,
Marc

[1] Just to demonstrate ease of use once setup:

  someCaptcha = new Captcha01();
  someCaptcha.doCaptcha(); # uses default captcha algo
  someCaptcha.setCaptchaBehavior(new UberCaptcha());
  someCaptcha.doCaptcha(); # uses UberCaptcha algo

UberCaptcha can, of course, be a variable passed from markup, and Class 
UberCaptcha included in, say, Page.php, or wherever.

[2] More OO stuff. Sorry.

You'd normally subclass behaviours from an interface, but interfaces are 
only supported from PHP5 on, so not an option for pmWiki. However, 
providing captcha algo writers implement an agreed set of methods, we 
could allow various common captcha algo behaviours, such as: slant 
angles, font size, font name, captcha image size, and so on. And all of 
these could be adjusted via markup, of course.





More information about the pmwiki-users mailing list