Using JCaptcha in your J2EE web Application
By Ahmed Hashim 23 June 2006
Introduction
Few months ago, it was my first time to know about JCaptcha. When I saw it, I
thought that it is really a great project. I tried to use it in a simple
application but few simple errors made me lazy to work through the test. Then,
one day some one said to me "Oh, there is a project to use JCaptcha and
it is a good sample and we can use it instead of trying to resolve the issues
in JCaptcha".
I said to myself, I am sure that this project is great and the JCaptcha
components are very simple and clear! Why not I test it really?
Also I want to make it easy for others tell all people that there is a great project working there.
This was the motivations to do this quick sample and I expect that I will spend some
time working through it and may contribute in it too.
What is captcha?
Captcha stands for Completely Automated Public Test to tell Computers and Humans Apart.
Captcha is a type of challenge-response test used in computing to determine whether or
not the user is human.
This can be achieved by displaying an image to the user contain some letters and the
user should enter it. Some programs can make pattern recognition and parse the
images and enter it again, so it is a challenge to create a readable, complex
and confusing image.
JCaptcha
JCaptcha is an OpenSource project developed to encapsulate the process of creating the
Turing message and validate the user input against the generated one. JCaptcha
is implementing many image processing and pattern recognition algorithms and
can be enhanced more and more every day.
It is a flexible, customized and easy to integrate engine.
Till now, JCaptcha can be integrated with any J2EE application. New modules
developed for Struts, Spring and for Roller Blogs.
JCaptcha Howto
Now, I am going to create a simple project to use JCaptcha in user login.
- Create a simple J2EE project using your preferred IDE.
-
Add the libraries required by JCaptcha jcaptcha-all.jar, ehcache.jar to
your application /WEB-INF/lib folder and add it to the project
libraries or class path. You will find the packages in bin-distribution
and ehcache
site
- Create a singleton service class to use it as a service provider for the JCaptcha.
- Create the JCaptcha Image Servlet which will generate the Servlet for every user request.
- Add the Servlet to web.xml
- Create JSP page and add the field Turing message to the form.
- Create the Servlet which will validate the user input including the Turing message.
- Add the login Servlet to web.xml
- Deploy your application to a Servlet container like Tomcat
- Run the application and test the login page
References
http://en.wikipedia.org/wiki/CAPTCHA
http://jcaptcha.sourceforge.net/
http://forge.octo.com/jcaptcha/confluence/display/general/Home
| Attachment | Size |
|---|---|
| login.jsp | 754 bytes |
| CaptchaServiceSingleton.java | 386 bytes |
| ImageCaptchaServlet.java | 2.45 KB |
| Login.java | 2.36 KB |
| web.xml | 992 bytes |
| jcaptcha.JPG | 8.1 KB |






JCaptcha is nice, but they
JCaptcha is nice, but they recently changed their license from LGPL to GPL, so I can't use it anymore. I switched to simplecaptcha.sf.net , which works well.
Michael
Have a look here, jcaptcha
Have a look here, jcaptcha is going back to lgpl
http://forge.octo.com/jcaptcha/confluence/display/general/Home