How can i prevent automated registrations using a (captcha) image?

In your user registration pages you may want to provide a generated image, which the user will be required to read and type its contents onto a text box. This will prevent automated bots etc. from filling up the form doing fake registrations.

What you need is:

A image tag in your user form, the src of it should point to a program (.jsp,struts-action etc.) which returns a randomly image (which has text), but before returning this program must store the image text in Session too, so that it when the form is submitted, you can retrieve what the user typed for the image text and compare it against what i stored in the session.

Not clear?

Ok your user form looks like this:

<form action=”/registerUser”>

Email: <input type=”text” name=”email”>

Name: <input type=”text” name=”thename”>

<img src=”/myapp/getMySecretImage.do”>

Type the image text here: <input type=”text” name=”thesecret”>

</form>

So, as you see above, the registration form has a image with an src that is pointing to a struts action. It could as well point to a JSP page or a CGI Script or whatever is capable of generating a image and returning.

Now, let us see what the image generation program looks like. Remember that it will not just return the image but also store the text that will display inside the image in user session.

So, if you are writing your struts action’s (/getMySecretImage) executre method will look like this (you can put the same thing in a servlet or JSP):