Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Implementing CAPTCHA, or...Are You Human?



After getting slammed two successive days earlier this week with Comment Spams for Sex Sites I took an hour to implement CAPTCHA on my blog. I based the component on Chris Kunicki's .text implementation described in his blog here and here, and on "BrainJar's" CAPTCHA Image component described in his Code Project article here.  Thank you Chris and BrainJar!

I took the GenerateRandomCode() component from the Default.aspx.cs in BrainJar's code and moved it to .Text UIData.cs class in Dottext.Web.UI Namespace and while I was at it made it static.  (Responders to Chris' source post couldn't find the method from the BrainJar class.)


private static Random random = new Random();

public static string GenerateRandomCode()
{
 string s = "";
 for (int i = 0; i < 3; i++)
  s = String.Concat(s, random.Next(10).ToString());
 return s;
}


Then I changed Chris's code to generate the AreYouHuman cookie value from this method.

Response.Cookies["AreYouHuman"].Value = UIData.GenerateRandomCode();

Besides that, I changed the source generating the Image in JpegImage.aspx.cs so the numbers would be a bit more readable.  All in all, cool AND fun.



Comments (0) | Post RSS RSS comment feed

Posted on 10/29/2004 10:47:00 AM by Dave Burke
Categories:
Tags:

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke