Project

General

Profile

Wiki » History » Version 4

Soh Keong, 09/22/2004 03:25 AM

1 1 Soh Keong
{{toc}}
2
3
h1. Wiki
4
5
h1. Guides
6
7
h2. Demo URL
8
9
The URL is:
10
> http://192.168.2.68:8080/TestPage/page/captcha/recaptcha.jsp
11
12
h2. Steps By Steps
13
14 4 Soh Keong
h3. Registration
15 1 Soh Keong
16
# Visit http://www.google.com/recaptcha/admin
17
# Sign in with your email and password (If no account with google, please proceed with sign up.)
18
# After sign in, Click on 'Add a New Site' button.
19
# Enter domain name in the text field, and click on the 'Create Key' button.
20
# Now, Public Key and Private Key is generated.
21
22
h3. Client site JSP 
23
24
<pre>
25
    <%@ page import="net.tanesha.recaptcha.ReCaptcha" %>
26
    <%@ page import="net.tanesha.recaptcha.ReCaptchaFactory" %>
27
28
    <html>
29
      <body>
30
        <form action="" method="post">
31
        <%
32
          ReCaptcha c = ReCaptchaFactory.newReCaptcha("your_public_key", "your_private_key", false);
33
          out.print(c.createRecaptchaHtml(null, null));
34
        %>
35
        <input type="submit" value="submit" />
36
        </form>
37
      </body>
38
    </html>
39
</pre>
40
41
h3. Server site JSP 
42
43
<pre>
44
    <%@ page import="net.tanesha.recaptcha.ReCaptchaImpl" %>
45
    <%@ page import="net.tanesha.recaptcha.ReCaptchaResponse" %>
46
47
    <html>
48
      <body>
49
      <%
50
        String remoteAddr = request.getRemoteAddr();
51
        ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
52
        reCaptcha.setPrivateKey("your_private_key");
53
54
        String challenge = request.getParameter("recaptcha_challenge_field");
55
        String uresponse = request.getParameter("recaptcha_response_field");
56
        ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, challenge, uresponse);
57
58
        if (reCaptchaResponse.isValid()) {
59
          out.print("Answer was entered correctly!");
60
        } else {
61
          out.print("Answer is wrong");
62
        }
63
      %>
64
      </body>
65
    </html>
66
</pre>
67
68
69
h3. DNS Caching (Important)
70
71
-Dsun.net.inetaddr.ttl=30 to your app-server to avoid connection between your server and reCAPTCHA to be interrupted every few months.
72 3 Soh Keong
* References: * 
73
# https://www.google.com/recaptcha (Retrieved 29 July2013)
74
# https://developers.google.com/recaptcha/docs/java (Retrieved 29 July2013)