2

I am developing a ReCaptcha for a site. Because of client's requirement, I cannot use Google ReCaptcha and anything in the cloud. Basically, I need a library that can be installed on my local machine, does not make remote request when I use it. The library must be able to run in Java.

I have been trying to find such thing, but have had no luck. Does anyone know any?

  • 2
    Finally a sane customer not only respecting privacy by declaration – I congratulate you to that! Just strip the "re" from "captcha" on your search, and you'll find some possible candidates (ReCaptcha AFAIK is the "brand name" Google gave theirs). There's an older collection at SO, another listing of Maven repos, there's also captcha.org with a long list (seemingly last updated in 2016). Sorry, II'm not a Java dev, so no clear answer – just this comment… – Izzy Jun 4 at 7:22
1

You could generate CAPTCHA images on your own server without connecting to any external servers as follows:

  1. Draw text on an image that contains letters and/or numbers.
  2. Use image processing to distort or camouflage the contents of the image to make it hard for OCR software to correctly read it.
  3. Display the image on the website, possibly with a secondary mechanism like asking a common-sense question from a question bank.

For the second step (image processing), the company I work for has an image processing Java library that contains hundreds of functions. I took sample images with digits in them and wrote code to perform random distortions on them. The attached image shows 2 input images alongside the output that resulted from running the code on them.

CAPTCHA screenshot

This is the code I used:

public void GenerateCaptcha(RasterImage image) {
   Random r = new Random(); 

   // Add some white noise to combat edge detection algorithms
   AddNoiseCommand addNoise = new AddNoiseCommand(50 + r.nextInt(50), RasterColorChannel.MASTER);
   addNoise.run(image);

   int stepDiv = 3;
   int xstep = image.getImageWidth() / (stepDiv + r.nextInt(stepDiv));
   int ystep = image.getImageHeight() / (stepDiv + r.nextInt(stepDiv));
   for (int x = 0; x < image.getImageWidth(); x += xstep)
   {
      for (int y = 0; y < image.getImageHeight(); y += ystep)
      {
         xstep = image.getImageWidth() / (stepDiv + r.nextInt(stepDiv));
         ystep = image.getImageHeight() / (stepDiv + r.nextInt(stepDiv));
         LeadRect rect = new LeadRect();
         rect.setLeft(x - xstep);
         rect.setTop(y - ystep);
         xstep = image.getImageWidth() * 2 / (stepDiv + r.nextInt(stepDiv));
         ystep = image.getImageHeight() * 2 / (stepDiv + r.nextInt(stepDiv));
         rect.setWidth(xstep);
         rect.setHeight(ystep);
         image.addEllipseToRegion(null, rect, RasterRegionCombineMode.SET);
         InvertCommand invert = new InvertCommand();
         int brightness = r.nextInt(400) - 200;
         ChangeIntensityCommand intensity = new ChangeIntensityCommand(brightness);
         intensity.run(image);
         invert.run(image);
         ystep = image.getImageHeight() / (stepDiv + r.nextInt(stepDiv));
      }
      xstep = image.getImageWidth() / (stepDiv + r.nextInt(stepDiv));
   }
   image.makeRegionEmpty();

   // Add a bit more white noise
   addNoise.run(image);
}

If you would like to try the library, there’s a free evaluation edition on this page.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.