# Implementation of google's recaptcha with ASP



## Sridhar_Rao (Sep 29, 2010)

A form in a html page (contact.htm) submits the data to asp script

```
<form name="test" method="post" action="cdosys.asp">
```
This code was downloaded from Internet.
I want to implement google lab's recaptcha on my form. I place the following code (as on their website) at the top of the page as rename my file as contact.asp

```
<%
  recaptcha_challenge_field  = Request("recaptcha_challenge_field")
  recaptcha_response_field   = Request("recaptcha_response_field")
  recaptcha_public_key       = "6LeYdL0SAAAAAJsYBKQI334EKlophwjQH8MXcma_" ' your public key
  recaptcha_private_key      = "6LeYdL0SAAAAAN8wYCezXdQeFodbYbw80dzVJxYs" ' your private key

  ' returns the HTML for the widget
  function recaptcha_challenge_writer()

  recaptcha_challenge_writer = _
  "<script type=""text/javascript"">" & _
  "var RecaptchaOptions = {" & _
  "   theme : 'clean'," & _
  "   tabindex : 0" & _
  "};" & _
  "</script>" & _
  "<script type=""text/javascript"" src=""*www.google.com/recaptcha/api/challenge?k=" & recaptcha_public_key & """></script>" & _
  "<noscript>" & _
    "<iframe src=""*www.google.com/recaptcha/api/noscript?k=" & recaptcha_public_key & """ frameborder=""1""></iframe><>" & _
      "<textarea name=""recaptcha_challenge_field"" rows=""3"" cols=""40""></textarea>" & _
      "<input type=""hidden"" name=""recaptcha_response_field""value=""manual_challenge"">" & _
  "</noscript>"

  end function

  ' returns "" if correct, otherwise it returns the error response
  function recaptcha_confirm(rechallenge,reresponse)

  Dim VarString
  VarString = _
          "privatekey=" & recaptcha_private_key & _
          "&remoteip=" & Request.ServerVariables("REMOTE_ADDR") & _
          "&challenge=" & rechallenge & _
          "&response=" & reresponse

  Dim objXmlHttp
  Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
  objXmlHttp.open "POST", "*www.google.com/recaptcha/api/verify", False
  objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  objXmlHttp.send VarString

  Dim ResponseString
  ResponseString = split(objXmlHttp.responseText, vblf)
  Set objXmlHttp = Nothing

  if ResponseString(0) = "true" then
    'They answered correctly
     recaptcha_confirm = ""
  else
    'They answered incorrectly
     recaptcha_confirm = ResponseString(1)
  end if

  end function

  server_response = ""
  newCaptcha = True
  if (recaptcha_challenge_field <> "" or recaptcha_response_field <> "") then
    server_response = recaptcha_confirm(recaptcha_challenge_field, recaptcha_response_field)
    newCaptcha = False
  end if

  %>
```
As you can see the form sends contents to cdosys.asp when submitted. I don't get how to implement recatcha here.
Any ideas??
Source: Using reCAPTCHA with Classic ASP - reCAPTCHA - Google Code


----------



## arpanmukherjee1 (Sep 30, 2010)

read the following lines ::



> *After* you've *signed up for your API keys*, you can add reCAPTCHA



use this:

Sign up for an API Key - Google Base Data API - Google Code


----------



## Sridhar_Rao (Sep 30, 2010)

Procuring the public and private keys was the first step. The keys are in right place, that is not the issue here.


----------

