Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a captcha in a java swing application

I need to add a captcha validator in a java swing application. I have been searching some libraries (JCaptcha and SimpleCatcha) but they are for web development.

Is there any library to use captcha on swing? and if it's not, is there a web page or repository with some captcha caracters to implement my own captcha?

I really appreciate your time and your help.

Thanks in advance.

like image 461
Hermandroid Avatar asked Oct 23 '22 16:10

Hermandroid


1 Answers

JCaptcha can return a BufferedImage. From there it is not much difficult to get the image visible using a JLabel:

BufferedImage captcha = // Get the captcha
// See also com.octo.captcha.service.image.AbstractManageableImageCaptchaService.getImageChallengeForID(String)
JLabel label = new JLabel(new ImageIcon(captcha));
// ... add that label to a visible container of your Swing application

In version 1.0, you can use this: http://jcaptcha.sourceforge.net/apidocs/1.0/com/octo/captcha/service/image/AbstractManageableImageCaptchaService.html

In 2.0-alpha1, there is this: http://jcaptcha.sourceforge.net/apidocs/2.0-alpha1/com/octo/captcha/service/image/AbstractManageableImageCaptchaService.html#getImageChallengeForID(java.lang.String)

You can also check the overloaded version of those methods with an extra Locale argument.

In each case, there is a default implementing class DefaultManageableImageCaptchaService.

like image 188
Guillaume Polet Avatar answered Oct 31 '22 12:10

Guillaume Polet