I hate spam, though I love getting comments on my blog. CKS:EBE has a feature for spam prevention using CAPTCHA which works well, though months ago I read this post and loved the concept that spam prevention could be socially beneficial. According to the reCAPTCHA site:

"About 60 million CAPTCHAs are solved by humans around the world every day. In each case, roughly ten seconds of human time are being spent. Individually, that’s not a lot of time, but in aggregate these little puzzles consume more than 150,000 hours of work each day. What if we could make positive use of this human effort? reCAPTCHA does exactly that by channeling the effort spent solving CAPTCHAs online into "reading" books."

I decided to extend CKS:EBE to use this valuable service and provide the code (99.99999% of which was NOT written by me) so that others could try it out. Please remember that this is a work in progress and depends on CKS:EBE for the base functionality. Use it at your own risk.

Implementing reCAPTCHA in CKS:EBE

I will be happy to provide my code after I have a chance to test it a bit more. If you cannot wait here is how I did it. BTW, I wanted to include the project in the CKS:EBE framework, so I changed the assembly name and namespace. I suppose you don’t need to do that, but it worked GREAT!

  1. Download the .Net code from the reCAPTCHA site. They have a bunch of examples, I used this one. (Written by Adrian Godong & Ben Maurer)
  2. Open the project and add a reference to CKS:EBE.
  3. Open RecaptchaControl.cs, RecaptchaResponse.cs, and RecaptchaValidator.cs and change the namespace to CKS.EBE.WebControls.
  4. In RecaptchaControl.cs locate the line:

    public RecaptchaControl()

  5.    Insert the next two lines at the top of the method:

    this.Enabled = BlogContext.Current.Settings.EnableCaptchaComments;

    this.Visible = this.Enabled;

  6. I also changed the name of the assembly to CKS.EBE.Recaptcha.dll and referenced the CKS:EBE strong name key file.

Deploy the reCAPTCHA Solution

  1. If you are going to deploy manually you need to copy the assembly to the server GAC.
  2. You also need to register the control as safe by adding the following line to the web.config file safecontrols section:

    <SafeControl Assembly="CKS.EBE.Recaptcha, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3e8b700c069fb747" Namespace="CKS.EBE.WebControls" TypeName="*" Safe="True" />

Register your site with reCAPTCHA

  1. You have to register your site to use the reCAPTCHA service. The process is easy and free.
  2. Sign up for the service here.
  3. Make note of your public and private keys as you will need the in the next section.

Add reCAPTCHA to your blog master

  1. You have to add the register clause to your master page.

    <%@ Register TagPrefix="recaptcha" Namespace="CKS.EBE.WebControls" Assembly="CKS.EBE.Recaptcha, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3e8b700c069fb747" %>

  2. Then add the control to your master. Locate the line:

    <EBE:CaptchaValidator id="idCaptchaValidator" runat="server" …

    and replace it with:

    <recaptcha:RecaptchaControl ID="recaptcha" runat="server" Theme="red" PublicKey="{your public key}" PrivateKey="{your private key}" />

     

  3. When you browse to your page you should see the reCAPTCHA control:reCAPTCHA Control 
  4. Test the control to ensure that it is working correctly.