Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

lets-blade/blade-patchca

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blade-Patchca: verification code library for Java

Overview

Simple yet powerful verification code library written in Java with zero dependency.

You can generate verification code picture like this:

sample

Steps to Integrate

  • Add following dependency in your pom.xml
<dependency>
    <groupId>com.hellokaton</groupId>
    <artifactId>blade-patchca</artifactId>
    <version>1.2.0</version>
</dependency>
  • Add following dependency in your code
ConfigurableCaptchaService cs = new ConfigurableCaptchaService();
cs.setColorFactory(new SingleColorFactory(new Color(25, 60, 170)));
cs.setFilterFactory(new CurvesRippleFilterFactory(cs.getColorFactory()));

FileOutputStream fos = new FileOutputStream("demo.png");
String challenge = EncoderHelper.getChallangeAndWriteImage(cs, "png", fos);
//Challenge text needs to be kept in the session for verification 
fos.close();
  • Use following code to create differnt types of captcha
switch (new Random().nextInt(5)) {
    case 0:
        cs.setFilterFactory(new CurvesRippleFilterFactory(cs.getColorFactory()));
        break;
    case 1:
        cs.setFilterFactory(new MarbleRippleFilterFactory());
        break;
    case 2:
        cs.setFilterFactory(new DoubleRippleFilterFactory());
        break;
    case 3:
        cs.setFilterFactory(new WobbleRippleFilterFactory());
        break;
    case 4:
        cs.setFilterFactory(new DiffuseRippleFilterFactory());
        break;
}