Project

General

Profile

Wiki » History » Revision 2

Revision 1 (Soh Keong, 09/22/2004 03:05 AM) → Revision 2/5 (Soh Keong, 09/22/2004 03:07 AM)

{{toc}} 

 h1. Wiki 

 h1. Guides 

 h2. Demo URL 

 The URL is: 
 > http://192.168.2.68:8080/TestPage/page/captcha/recaptcha.jsp 

 h2. Steps By Steps 

 h3. Create Public Key and Private Key 

 # Visit http://www.google.com/recaptcha/admin 
 # Sign in with your email and password (If no account with google, please proceed with sign up.) 
 # After sign in, Click on 'Add a New Site' button. 
 # Enter domain name in the text field, and click on the 'Create Key' button. 
 # Now, Public Key and Private Key is generated. 

 h3. Client site JSP  

 <pre> 
     <%@ page import="net.tanesha.recaptcha.ReCaptcha" %> 
     <%@ page import="net.tanesha.recaptcha.ReCaptchaFactory" %> 

     <html> 
       <body> 
         <form action="" method="post"> 
         <% 
           ReCaptcha c = ReCaptchaFactory.newReCaptcha("your_public_key", "your_private_key", false); 
           out.print(c.createRecaptchaHtml(null, null)); 
         %> 
         <input type="submit" value="submit" /> 
         </form> 
       </body> 
     </html> 
 </pre> 

 h3. Server site JSP  

 <pre> 
     <%@ page import="net.tanesha.recaptcha.ReCaptchaImpl" %> 
     <%@ page import="net.tanesha.recaptcha.ReCaptchaResponse" %> 

     <html> 
       <body> 
       <% 
         String remoteAddr = request.getRemoteAddr(); 
         ReCaptchaImpl reCaptcha = new ReCaptchaImpl(); 
         reCaptcha.setPrivateKey("your_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> 
 </pre> 


 h3. DNS Caching (Important) 

 -Dsun.net.inetaddr.ttl=30 to your app-server to avoid connection between your server and reCAPTCHA to be interrupted every few months. 
 * NOTE : * refer to https://developers.google.com/recaptcha/docs/java (Last accessed on 29 July 2013)