#1
  1. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Dec 2005
    Posts
    261
    Rep Power
    13

    Google Recaptcha and ASP.NET


    Hello

    I have managed to add the Google Recaptcha to my aspx form and it looks like this:



    Basically, I added this in my <head> tags: <script src='https://www.google.com/recaptcha/api.js'></script> and this inside my <form> tags:

    <div class="g-recaptcha" data-sitekey="****************************************" ></div>

    To complete the Google Recaptcha set up, do I need to add something like this in my aspx.vb file?

    Code:
    Protected Sub contact_submitted_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles contact_submitted.Click
    
    Private Function IsGoogleCaptchaValid() As Boolean
        Try
            Dim recaptchaResponse As String = Request.Form("g-recaptcha-response")
            If Not String.IsNullOrEmpty(recaptchaResponse) Then
                Dim request As Net.WebRequest = Net.WebRequest.Create("https://www.google.com/recaptcha/api/siteverify?secret=************************************&response=" + recaptchaResponse)
                request.Method = "POST"
                request.ContentType = "application/json; charset=utf-8"
                Dim postData As String = ""
    
                'get a reference to the request-stream, and write the postData to it
                Using s As IO.Stream = request.GetRequestStream()
                    Using sw As New IO.StreamWriter(s)
                        sw.Write(postData)
                    End Using
                End Using
                ''get response-stream, and use a streamReader to read the content
                Using s As IO.Stream = request.GetResponse().GetResponseStream()
                    Using sr As New IO.StreamReader(s)
                        'decode jsonData with javascript serializer
                        Dim jsonData = sr.ReadToEnd()
                        If jsonData = "{" & vbLf & "  ""success"": true" & vbLf & "}" Then
                            Return True
                        End If
                    End Using
                End Using
            End If
        Catch ex As Exception
            'Dont show the error
        End Try
        Return False
    End Function
    
    End class
    I can't test it yet as the file is not compiled, but is that the kind of thing Google is expecting? Their tutorial
    https://www.google.com/recaptcha/intro/index.html is not too clear.

    Thank you.
  2. #2
  3. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Aug 2008
    Location
    USA
    Posts
    1,606
    Rep Power
    347
    have a look at this example

    https://www.google.com/recaptcha/api2/demo

    and you can view source by right click on page and select view source option. this is pretty simple and easy as well.

    Comments on this post

    • SteveHigh agrees : Looks useful, thanks!
    if you found this post is useful click Give Rep button (bottom side on this reply ) and agree

    Jquery Shake Effect ,
    Andriod KitKat


    Thank You,
    KiranK
  4. #3
  5. No Profile Picture
    Registered User

    Join Date
    Aug 2015
    Posts
    5
    Rep Power
    0
    Hi MarkWilson, thanks for sharing this captcha demo, it really helped.
  6. #4
  7. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Aug 2008
    Location
    USA
    Posts
    1,606
    Rep Power
    347
    Originally Posted by CalvinOcean
    Hi MarkWilson, thanks for sharing this captcha demo, it really helped.

    Thanks !! It helped you

Similar Threads

  1. ASP script form mailer / recaptcha
    By towreg in forum ASP Development
    Replies: 0
    Last Post: February 14th, 2011, 06:44 PM
  2. Using An ASP Form With Recaptcha
    By Misty in forum ASP Development
    Replies: 6
    Last Post: September 25th, 2009, 05:36 PM
  3. Google's Buy of reCAPTCHA Hurt Internet Security? (PC World)
    By RSS_News_User in forum Technology News
    Replies: 0
    Last Post: September 17th, 2009, 01:03 PM
  4. Google Will Buy reCAPTCHA To Help Scan Books (NewsFactor)
    By RSS_News_User in forum Technology News
    Replies: 0
    Last Post: September 17th, 2009, 12:05 PM
  5. ASP Gurus: Please Help - reCaptcha for ASP
    By djkfunk in forum ASP Development
    Replies: 1
    Last Post: April 24th, 2009, 04:38 PM

IMN logo majestic logo threadwatch logo seochat tools logo