Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Google Recaptcha 2.0 in ASP Classic?

Tags:

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

like image 483
Ed Dias Avatar asked Jun 08 '15 14:06

Ed Dias


People also ask

Can I run reCAPTCHA v2 and v3 on the same page?

Can I use reCAPTCHA with third party solutions? Yes, you can use both reCAPTCHA (non-Enterprise version) and reCAPTCHA Enterprise. Typically the third party solution asks for your public key and either your secret key or your API key.

Which reCAPTCHA should I use v2 or v3?

What is the difference between reCAPTCHA v2 and v3? ReCAPTCHA v2 requires the user to click the “I'm not a robot” checkbox and can serve the user an image recognition challenge. ReCAPTCHA v3 runs in the background and generates a score based on a user's behavior. The higher the score, the more likely the user is human.


1 Answers

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>
like image 78
Zam Avatar answered Sep 29 '22 10:09

Zam