Web
Guillermo Castro  

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/action.properties 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:

addComment=org.javageek.pebble.controller.action.AddCommentAction

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:

<tr>
<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>
<c:set var="captcha2" scope="session">
<%= rnd.nextInt(10) + 1 %>
</c:set>
<c:out value="${captcha1}"/> + <c:out value="${captcha2}"/> =
</b>
</td>
<td><input type="text" name="captcha" size="2"/> (Helps stop blog spam)</td>
</tr>

2 thoughts on “Adding Captcha to your Pebble blog

  1. Vaibhav

    Hi,

    I want to enable E-mail notifications in Pebble, but I dont know how to do that.

    It would be great if you can help me out.

    Thanks in Advance

    Vaibhav

    [email protected]

  2. Anonymous

    Thanks

Leave a Reply