Git Product home page Git Product logo

kaptcha-spring-boot-starter's Introduction

kaptcha-spring-boot-starter

Maven Central Sonatype Nexus (Snapshots) License

Kaptcha for spring boot autoconfigure.

1. Maven

<dependency>
    <groupId>com.youkol.support.kaptcha</groupId>
    <artifactId>kaptcha-spring-boot-starter</artifactId>
    <version>LATEST_VERSION</version>
</dependency>

2. Config spring-boot application.yml

# Support zero-configuration mode, it will running by the default value.
# For Example:
youkol:
  web:
    kaptcha:
      enabled: true
      servlet:
        enabled: true
        url-mapping: /kaptcha
        size-param: size
        font-size-param: fontSize
      cache:
        # cache.type = session or redis.
        type: session
        token-name: YOUKOL-KAPTCHA-TOKEN
        timeout: 300000
      config:
        kaptcha:
          #
          # Note: To avoid syntax errors in yaml files,
          #       when border property is "no", don't set value of border color and border thickness.
          #       when border property is "yes", You must omit the border property setting and
          #       set value of border color and border thickness directly.
          #
          #       Take a look at the following example:
          #           1) Hide border
          border: "no"
          #           2) Show border
          # border:
          #   color: "105,179,90"
          #   thickness: 1
          producer:
            impl: com.google.code.kaptcha.impl.DefaultKaptcha
          textproducer:
            # simple math text creator, for example `7+8=?`
            # impl: com.youkol.support.kaptcha.text.impl.SimpleMathTextCreator
            impl: com.google.code.kaptcha.text.impl.DefaultTextCreator
            char:
              string: abcde2345678gfynmnpwx
              length: 5
              space: 2
            font:
              names: \u5fae\u8f6f\u96c5\u9ed1,Arial,\u5b8b\u4f53,\u6977\u4f53
              size: 40
              color: BLUE
          noise:
            impl: com.google.code.kaptcha.impl.NoNoise
            color: BLACK
          obscurificator:
            impl: com.google.code.kaptcha.impl.WaterRipple
          word:
            impl: com.youkol.support.kaptcha.text.impl.SimpleWordRenderer
          background:
            impl: com.google.code.kaptcha.impl.DefaultBackground
            clear:
              from: LIGHT_GRAY
              to: WHITE
          image:
            width: 200
            height: 50

3. Send Request Url

GET http(s)://{host}:{port}/{contextPath}/{urlMapping}
For example:

  1. response image

    Request: GET http://localhost:8080/kaptcha
    Response: kaptcha image (image/jpeg)

  2. response json

    Request: GET http://localhost:8080/kaptcha?format=base64
    Response:

      {   
        "code": "200",    
        "message": "OK",    
        "data": {    
          "uuid": "f7e7001f042a47eaa73dcdafe01a7b9d",    
          "image": "data:image/jpeg;base64,/9j/4AA...RRRQB//9k="   
        }
      }  
    

4. validate image code

sample code:

// For example:
@Autowired
private KaptchaCacheResolver kaptchaCacheResolver;

public Object login(HttpServletRequest request) {
    // some things.
    // valid Kaptcha
    String code = request.getParameter("code");
    boolean bValid = kaptchaCacheResolver.validKaptcha(request, code);
    // other things.
}

Note: when use redis mode, you must put token-name and token-value in request header.

  • token-name: youkol.web.kaptcha.cache.token-name
  • token-value: the uuid of response (The uuid also can get from response header)

About Kaptcha

Please see more information about this project.
http://code.google.com/p/kaptcha/

kaptcha-spring-boot-starter's People

Contributors

jackiea avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.