Search code examples
asp-classic

How to implement Google Recaptcha 2.0 in ASP Classic?


I need help to implement the answer Google Recaptcha 2.0.

I've tried a few ways to recover the response after sending the form but not consigui get the answer True.

Follows the example I'm trying:

recaptcha_secret = "example45454sasa"

sendstring = _
"https://www.google.com/recaptcha/api/siteverify?" & _ 
"secret=" & recaptcha_secret & _
"&response=" & request.form("g-recaptcha-response")

Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.Open "GET", sendstring , false

objXML.Send()

if instr(objXML.responseText,"true") then
    response.write "yes"
else
    response.write "no"
end if

Second exmeplae wehre I using aspJSON1.17.asp library:

recaptcha_secret = "example45454sasa"

Set oJSON = New aspJSON

jsonstring = "https://www.google.com/recaptcha/api/siteverify?secret=" & recaptcha_secret & "&response=" & request.form("g-recaptcha-response") & ""

'Load JSON string
oJSON.loadJSON("" & jsonstring & "")

'Get single value
Response.Write oJSON.data("success") & ""

The two examples above return False or No.

How do I implement a way to check that Recaptcha were marked?

*reCaptcha Documentatiom

Thanks for yout attention!


In the case of Zam as in my example the response that appears on the screen is:

Response: { "success": false, "error-codes": [ "invalid-input-secret" ] }

I believe it should appear "True" since I am answering the question correctly.

You can test: bit.ly/1R1cbEs


Solution

  • I don't see how you send request.

    Anyway, below is working sample with my site key for test web site. Of course, you should provide your own "secret key" and "data-sitekey"

    Live sample: http://1click.lv/googlecaptcha.asp

    File name: GoogleCaptcha.asp

    <%@LANGUAGE=VBSCRIPT%>
    <%
        Option Explicit
    %>
    <html>
        <head>
            <script src="https://www.google.com/recaptcha/api.js" async defer></script>
        </head>
    
        <body>
            <h4>http://stackoverflow.com/questions/30711884/how-to-implement-google-recaptcha-2-0-in-asp-classic/30735079</h4>
    <%
        If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
            Dim recaptcha_secret, sendstring, objXML
            ' Secret key
            recaptcha_secret = "6LfUUwgTAAAAAMQy5tz9u1BMSnCQV1CVh5tuBcEF"
    
            sendstring = "https://www.google.com/recaptcha/api/siteverify?secret=" & recaptcha_secret & "&response=" & Request.form("g-recaptcha-response")
    
            Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
            objXML.Open "GET", sendstring, False
    
            objXML.Send
    
            Response.write "<h3>Response: " & objXML.responseText & "</h3>"
    
            Set objXML = Nothing
        End If
    %>
    
            <form method="post" action="GoogleCaptcha.asp">
                <!-- Site key -->
                <div class="g-recaptcha" data-sitekey="6LfUUwgTAAAAAAQZPb6j22A2a2tZoAUygdmqpgdv"></div>
                <br />
                <input type="submit" value="Try">
            </form>
        </body>
    </html>