Google Kaptcha Generate graphics verification code

Source: Internet
Author: User
Tags border color generator

Google Captcha is a tool class for Google to generate a verification code by saving randomly generated strings to the session and returning them to the page as pictures, before the foreground page is submitted to the background for comparison.

Dependent libraries can go to Maven repository view:


But I did not download it, and then chose to put the jar package after the download to the project Lib, in the footsteps of Gradle through the compilation.

Compile Filetree ("$rootDir/lib") {
        include ' Kaptcha-2.3.jar '
    }

Online said can from Ali's maven warehouse download, download speed is OK, very stable, with address: http://maven.aliyun.com/nexus/#welcome, at the end of the article I will give the author link.

Google Captcha can be configured as follows:

Kaptcha.border whether there is a border default to True we can set the Yes,no kaptcha.border.color border color by default to Color.Black kaptcha.border.thickness Border thickness default to 1 Kaptcha.producer.impl Authenticode generator defaults to Defaultkaptcha kaptcha.textproducer.impl Authenticode text generator defaults to Defaulttextcrea Tor kaptcha.textproducer.char.string code text character content range default to abcde2345678gfynmnpwx kaptcha.textproducer.char.length captcha text Word Character length default to 5 kaptcha.textproducer.font.names captcha text font style default to New font ("Arial", 1, fontSize), New Font ("Courier", 1, Fontsi Ze) kaptcha.textproducer.font.size Verification code text character size default to Kaptcha.textproducer.font.color captcha text character color default to Color.Black KAP Tcha.textproducer.char.space captcha text character spacing defaults to 2 Kaptcha.noise.impl captcha Noise Generation object defaults to Defaultnoise Kaptcha.noise.color Code noise color Default to Color.Black Kaptcha.obscurificator.impl CAPTCHA style engine default to Waterripple Kaptcha.word.impl captcha text character render default to Defau Ltwordrenderer Kaptcha.background.impl Verification Code Background generator defaults to defaultbackground kaptcha.background.clear.from captcha background color progressive defaults Think Color.light_gray kapTcha.background.clear.to Verification Code Background color Progressive default to Color.White kaptcha.image.width verification code picture width default to a kaptcha.image.height verification code map The slice height defaults to 50
Configure the servlet mapping (the simplest way to configure the interface to get the CAPTCHA, or you can configure it via SPRINGMVC)

Web. XML configuration under the website project

 <servlet> <servlet-name>Kaptcha</servlet-name> <servlet-class>com.google.code.kaptcha.se Rvlet.
      Kaptchaservlet</servlet-class> <init-param> <param-name>kaptcha.border</param-name> <param-value>no</param-value> </init-param> <init-param> <param-name>kaptcha 
    .textproducer.char.string</param-name> <param-value>02345689</param-value> </init-param> <init-param> <param-name>kaptcha.background.clear.from</param-name> <param-value> White</param-value> </init-param> <init-param> <param-name>kaptcha.background.clear.
      to</param-name> <param-value>white</param-value> </init-param> <init-param> <param-name>kaptcha.obscurificator.impl</param-name> <param-value>com.google.code.kaptcha.imp L.waterripple</param-value> </init-param> <init-param> <param-name>kaptcha.noise.color</param-name&gt
      ; <param-value>255,96,0</param-value> </init-param> </servlet> <servlet-mapping> & Lt;servlet-name>kaptcha</servlet-name> <url-pattern>/images/captcha.jpg</url-pattern> </ Servlet-mapping>

Start service, Access: Http://localhost:8140/auth-server/images/captcha.jpg You can see the effect.


Reference: Generate a verification code using Googlekaptcha in the SPRINGMVC project

Springmvc using Google Captcha to generate a picture verification code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.