NP – Asirra

      1 Comment on NP – Asirra

Recently, I’ve read an article about the Asirra web service, which is a HIP, CAPTCHA alternative, that works by asking users to identify photographs of cats and dogs. I really liked that idea, so I decided to create Asirra implementation for my favorite PHP framework – Zend Framework.

NP – Asirra package provides API for using and implementing Asirra web service in some project that is powered by Zend Framework. I hosted this project on Google Code and you can check it out here. Also, here is a direct link for downloading NP-Asirra package.

There are several classes in the NP-Asirra package. There’s a service class – NP_Service_Asirra, which provides a client for consuming Asirra. Developers can use it independently, in order to generate HTML code for outputting Asirra challenge, or validating user’s input. As the Asirra web service allows developer to customize look of the Asirra challenge, through SetEnlargedPosition() and SetCellsPerRow() JS methods, those can be set through this service class. Here are some examples:

Also, this package provides approprite CAPTCHA adapter – NP_Captcha_Assira, which utilize NP_Service_Asirra in order to generate and validate Asirra challenge. A typical use case might look like the following:

And here’s an important note… As Asirra implementation requires JS Asirra_CheckIfHuman() function to be called, so that client side validation can be executed, in both of those examples above, you must
manually make sure that that function is called before submit form in which you’ve placed Asirra.

If you decide to use Asirra CAPTCHA adapter along with Zend_Form_Element_Captcha, that problem can be bypassed, because this adapter has its own decorator, which injects necessary JS code, that will try to intercept submit event on the parent form and execute Asirra_CheckIfHuman() function. jQuery library, served by Google’s API, is utilized for this purpose.

Still, if you want handle all that JS job by yourself, you can disable usage of above mentioned decorator, by setting $_useJsDecorator flag to boolean false:

Here’s an example of how Asirra CAPTCHA adapter can be used in Zend_Form_Element_Captcha implementation:

You’ll notice that you must also add prefix/path to the AsirraCheckIfHuman decorator, if you decide to use it.