`

reCAPTCHA

阅读更多

reCAPTCHA 是卡内基梅隆大学的一帮人搞出来的,它的技术并没有什么先进之处,但是创意有点意思。世界上面有很多将图书电子化的计划,基本是把书籍扫描了以后用 OCR 软件识别。有些情况下面 OCR 软件自己觉得某些词的识别结果并不是非常有把握。通常情况下面是通过雇佣劳力来肉眼校对。reCAPTCHA 项目认为这个工作不妨交给全世界大量填写认证码的人来完成。

一般图形认证码系统都是只生成一个单词的,reCAPTCHA 生成的图片里面有两个单词,其中一个是机器生成的,有正确结果的单词,另一个则是扫描出来的有问题的单词,这个词没有正确结果。如果用户提交上来的结果里 面机器生成的那个是对的,那么系统就认为另外一个也很有可能是对的。一幅扫描图片展示给多个用户如果结果都是一样的,他就将这个结果作为最终校对结果。这 样就实现了利用人力来分布式校对文稿的目的。更具体的细节可以看 http://recaptcha.net/learnmore.html

There are three ways to use reCAPTCHA: using an application plugin, using a library for your programming language, and using the web-based API.

How to reCAPTCHA Your Java Application:http://wheelersoftware.com/articles/recaptcha-java.html

 

在你的pom.xml文件加入:

 <dependency>
                <groupId>net.tanesha.recaptcha4j</groupId>
                <artifactId>recaptcha4j</artifactId>
                <version>${version}</version>
        </dependency>
    ...
    
    <repositories>
        ...
        <repository>
                        <id>taneshanet</id>
                        <url>http://tanesha.net/maven2</url>
                </repository>
        ...
    </repositories>

 在你的jsp页面这样:

<%
        // create recaptcha without <noscript> tags
        ReCaptcha captcha = ReCaptchaFactory.newReCaptcha("my-public-key", "my-private-key", false);
        String captchaScript = captcha.createRecaptchaHtml(request.getParameter("error"), null);
        
        out.print(captchaScript);
%>

 Checking the captcha goes like this:

<%
        // create recaptcha without <noscript> tags
        ReCaptcha captcha = ReCaptchaFactory.newReCaptcha("my-public-key", "my-private-key", false);
        ReCaptchaResponse response = captcha.checkAnswer(request.getRemoteAddr(), request.getParameter("recaptcha_challenge_field"), request.getParameter("recaptcha_response_field"));

        if (response.isValid()) {
                out.print("Success");
        }
        else {
                out.print(response.getErrorMessage());
        }
%>

  https://svn.tanesha.net/svn/sandbox/recaptcha4j-example/trunk/ .

当然你也可以在spring里面配置:

<bean id="reCaptcha" class="net.tanesha.recaptcha4j.ReCaptchaImpl">
                <property name="privateKey" value="my private key" />
                <property name="publicKey" value="my public key" />
                <property name="recaptchaServer" value="http://api.recaptcha.net" />
                <!-- Or, if you want to use SSL, then use this:
                        <property name="recaptchaServer" value="http://secure-api.recaptcha.net" />
                -->
                <property name="includeNoscript" value="false" />
        </bean>

 http://tanesha.net/projects/recaptcha4j/

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics