Java Humanizer is an alternative to using CAPTCHA on your site. It's heavily inspired by the fantastic Humanizer project for Rails applications.
Java Humanizer works by providing a properties file containing simple questions and their answers. The questions are easily answered by humans, but provide enough of a challenge for scripts to stop unwanted form submissions.
Download the jar file and add to your project's classpath.
Get an instance of the Humanizer class:
Humanizer humanizer = new Humanizer();
Ask it for a random question:
Question question = humanizer.getQuestion();
Display the question in your JSP:
<input type="hidden" name="humanizerQuestionId" value="${humanizerQuestion.id}" />
<label for="humanizerAnswer">${humanizerQuestion.question}</label>
<input type="text" id="humanizerAnswer" name="humanizerAnswer" size="64" />
In your action, check the answer:
long id = // get question id from paaramters
String answer = // get answer from parameters
boolean isHuman = Humanizer.checkAnswer(id, answer);
The jar file comes with a properties file containing a set of questions and answers embedded within the jar, but you can easily provide your own set.
The format for this file is:
question.<n>=Question goes here
answer.<n>=Answer1; Answer2
When the file is parsed, the value of is used as the question's ID so we can find the correct set of answers. Multiple answers are supported for each question, which allows for variations of the answer. For example:
question.1=Two plus two?
answer.1=4; four
This allows the question to be answered with either the number 4 or the word "four".
To use a custom set of questions and answers, just provide Humanizer with a Properties object that has your custom set of questions and answers loaded.
String file = "..."; // location of custom questions and answers
Properties props = new Properties();
props.load(file);
Humanizer humanizer = new Humanizer(props);
The questions included in this project are taken directly from Humanizer by Kisko Labs
Java Humanizer is licensed under the MIT License, for more details see the LICENSE file.