Java Arabic Captcha using SimpleCaptcha Library


In this post, I will introduce how to use SimpleCaptcha to generate Arabic Captcha images to include in Arabic Portals.

How SimpleCaptcha works

The open source library introduced by SimpleCaptcha, is based on a servlet that generates the captcha image object, set it as attribute in the request(so it can be accessible to validate the user’s input) then writes it to the response as an PNG image.

The servlet could be mapped to a context that looks similar to image URL on the web like :


Then in the servlet/struts action or whatever place you need to validate the user’s input against the generated Captcha object, process the request or not. You get the captcha object from the request and validate it like this :

String userInputCaptcha = request.getParameter("userInputCaptcha");
nl.captcha.Captcha captchaObj = (Captcha) session.getAttribute("simpleCaptcha");
if (captcha != null && !captcha.isCorrect(userInputCaptcha.toLowerCase()))
// Process the request
// display captcha input error


Generating the Arabic Captcha

In order to generate Arabic Captcha, We need to develop three classes :

  • WordRenderer : We need to develop a class that implements the interface nl.captcha.text.renderer.WordRenderer to override the generation of the word to reverse it, as the Arabic words are read right-to-left not left-to-right as English ūüôā
  • CaptchaServlet : We need to develop the captcha servlet that will use our developed ArabicWordRenderer class and passes the 28 Arabic Alphabet characters to the Default DefaultTextProducer.

The generated Arabic captcha looks like this screenshot :

Arabic Captcha

The source files

I included the source code of the 2 classes to be downloaded here.

Categories JavaTags , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close