Google verification code

Original Essay] The powerful Google open source free verification code reCAPTCHA








1, first visit http://code.google.com/intl/zh-CN/apis/recaptcha/intro.html, then click the corresponding language on the left, bloggers use the example jsp, so to download the jar package, you can directly [click here to download the jar package] to decompress the recaptcha4j-0.0.7.jar in the zip to the web project lib.



2. Visit https://www.google.com/recaptcha/admin/create and log in with your google account, enter the URL of your website in the text box, such as global-key.mycompany.com, click create key to generate Public Key and Private Key.



3. Write an example form in jsp



<%@ page import="net.tanesha.recaptcha.ReCaptcha" %> <%@ page import="net.tanesha.recaptcha.ReCaptchaFactory" %> <html> <body> <form action="" method="post"> <% ReCaptcha c = ReCaptchaFactory.newReCaptcha("fill in the previously generated public_key", "fill in the previously generated private_key", false); out.print(c.createRecaptchaHtml(null, null)); %> <


4,编写示例服务端接收校验



<%@ page import="net.tanesha.recaptcha.ReCaptchaImpl" %>    <%@ page import="net.tanesha.recaptcha.ReCaptchaResponse" %>    <html>      <body>      <%        String remoteAddr = request.getRemoteAddr();        ReCaptchaImpl reCaptcha = new ReCaptchaImpl();        reCaptcha.setPrivateKey("填入之前生成的private_key");        String challenge = request.getParameter("recaptcha_challenge_field");        String uresponse = request.getParameter("recaptcha_response_field");        ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, challenge, uresponse);        if (reCaptchaResponse.isValid()) {          out.print("Answer was entered correctly!");        } else {          out.print("Answer is wrong");        }      %>      </body>    </html>





Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326992793&siteId=291194637