How to create an Ajax Captcha with less then 50 lines of C#

28. May 2007

According to WikiPedia the meaning of the word Captcha is Completely Automated Public Turing test to tell Computers and Humans Apart! And it's basic purpose is as its name suggests to be able to check automatically if your users are Humans or Computers!

They're often used in association with comments on blogs, user signup forms or forum submit new post systems etc. Basically any place you'd like to avoid automated systems get to play with your own system. In most cases they're basically used as spam protection

Gaia Ajax Widgets has one neat little control which is called Gaia DynamicImage which I still am pretty stunned about that none of our competitors have copied since the process to create such "Dynamic Images" in ASP.NET by hand is quite a nightmare!

In this example I've basically just added a DynamicImage which in the RetrieveImage Event returns an image containing some random letters which are set in the Page_Load by using our Session Object. Then when the user is supposed to submit the data where we should check if he's human or not we can compare the Session random text value against the Text property of some TextBox object contained on the same page.

For clarity I've removed everything that doesn't have to do directly with creating the Captcha.

Note also that like most things you can do in Gaia there's not one single line of "custom" JavaScript here! Everything is done in C# or declaratively in the .ASPX file!



The Captcha Code



The .aspx declarative code


The C# codebehind


You might think I'm playing you here, but this is everything needed to create an Ajax Captcha thanx to Gaia Ajax Widgets!
Have fun :)
The Ajax Library enabling this can be found in our main Ajax Library Website

AddThis Social Bookmark Button Add to DZone AddThis Feed Button

 
Legal note: the meaning and content expressed on these blogs don't necassary correspond with the meaning of the legal company Gaiaware AS, but are considered to be personal opinions and expressions.