Matthew McDermott, MVP

General ramblings from a SharePoint MVP about SharePoint and Microsoft technologies related to collaboration, web content management and productivity.

Socially Conscious Spam Prevention

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.
Posted by Matthew McDermott on Friday, 23 Nov 2007 09:57
5 Comments | Filed under: Community Kit for SharePoint
Bookmark this post with:        

Comments

On 23 Nov 2007 10:25, Willa said:

Very cool, I'd love the code when you are ready!

On 23 Nov 2007 09:31, AC [MVP MOSS] said:

Have you looked at http://akismet.com/? Similar concepts without the requirement force commenters to use CAPTCHA.

On 24 Nov 2007 06:20, Matthew said:

I have, in fact CKS:EBE has Akismet checking built in. I like the fact that the CAPTCHA is helping with books for the blind.

On 30 Nov 2007 04:45, Wayne said:

Yeah, I was going to comment about akismet also. I should mention that the 10 or so times I've encountered recaptcha, the darn things didn't work one whip for me and I ended up having to bail on writing the comments. And what is this CKS:EBE thing? Is it like SETI but we're looking for seebie? (seek seebie?)

On 03 Dec 2007 06:41, Matthew said:

Wayne, CKS:EBE is the engine that runs this blog. It is a community project that extends and enhances the SharePoint blog API. Look at my first Building a Blog Host article.

Leave a comment

Name (required)

Url

Email

Comments

Complete this section to post your comment