Adding Captcha to your Pebble blog

I started getting some spam comments on my blog a couple of weeks ago, at a steady increasing rate, which was getting very annoying. Fortunately, I found a very simple way to add captcha validation to the add comments form. Unfortunately, Glen’s solution involved patching the original pebble source and redeploying pebble. There is a better way, as I commented on his blog, which is to modify the  addComment property inside the WEB-INF/classes/ file to point to a new class where you add the captcha functionality. The main advantage of doing this is that you don’t need to redeploy pebble, as you are only adding a new library.

To make things even simpler, I’m making the ‘plugin’ (which is only the new class) available for download. You only need to put this jar in the WEB-INF/lib folder of your pebble deployment, and modify the above property to look like this:


Then restart pebble, and enjoy a spam-free blog, at least until the damn spammers figure out how to deal with captchas.

UPDATE: I forgot to mention that you also need to modify common/jsp/commentsForm.jspf to add the captcha validation:

<td valign="top"><b>Math Quiz
<% java.util.Random rnd = new java.util.Random(); %>
<c:set var="captcha1" scope="session">
<%= rnd.nextInt(10) + 1 %>
<c:set var="captcha2" scope="session">
<%= rnd.nextInt(10) + 1 %>
<c:out value="${captcha1}"/> + <c:out value="${captcha2}"/> =
<td><input type="text" name="captcha" size="2"/> (Helps stop blog spam)</td>

2 thoughts on “Adding Captcha to your Pebble blog

Leave a Reply