NetTalk Central

Author Topic: CAPTCHA Example  (Read 10796 times)

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
CAPTCHA Example
« on: June 24, 2010, 08:41:48 AM »
Special thanks to Bill Shields.  Without him I could not have put this together.

I have attached a zip file containing a web app that has a CAPTCHA.

The app was compiled using Clarion 7.2 7248.   

Solution requires NetTalk and WinEvent

The login name is: demo.  The password is: demo

You will have to setup an account with reCaptcha.  They use an IP address to issue a public key and a private key.  You will need these keys in your code.

For testing purposes, I used the IP address to my home's cable modem.

There's a text file named YourJavascriptCode.  There's some info for you in there.

If you have any questions, please ask them here.

Don

[attachment deleted by admin]
« Last Edit: June 24, 2010, 08:49:03 AM by DonRidley »
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: CAPTCHA Example
« Reply #1 on: June 24, 2010, 08:51:40 AM »
Here's a screenshot of it in action....



[attachment deleted by admin]
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Re: CAPTCHA Example
« Reply #2 on: July 22, 2010, 01:53:16 PM »
Hi Don,

I am very interested in your captcha example.
I am on 6.3 though so it is hard for me (and others) to check it out.
Is there any way for me to get hold of a 6.3 version?

Rene Simons
Rene Simons
NT14.14

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: CAPTCHA Example
« Reply #3 on: July 23, 2010, 06:43:07 AM »
I would love to but I don't own a copy of C6.x .  Here's a brief overview:

Create an WebForm procedure.

Create local variable: lresponse

I have the lresponse variable in the "fields" section of the form but it is hidden with no prompt.

Insert code into embeds:

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Validate lresponse

lResponse = PostFormResponse('http://api-verify.recaptcha.net/verify','privatekey=6LdXErsSAAAAAKEj4LSWqHjjheCDqwWiUkPEGr7o &remoteip='&p_web.RequestData.FromIP&'&challenge='&CLIP(p_web.GetValue('recaptcha_challenge_field'))&'&=&response='&p_web.GetValue('recaptcha_response_field'))

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Validate lresponse (same embed but used twice..see attached screenshot)

IF INSTRING('true',clip(lresponse),1,1)
    !loc:invalid = 'lresponse'
    !loc:alert = 'The captcha words are incorrect!'
ELSIF INSTRING('false',clip(lresponse),1,1)
    loc:invalid = 'lresponse'
    loc:alert = 'The captcha words are incorrect!'
END

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Create a standard Window procedure

Create local variable: MyText String (1024)

Insert code into embed points:

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

ErrorTrap PROCEDURE(string errorDtr.string fundtionName),VIRTUAL

Before Parent Call

    MyText = ''
    POST(Event:CloseWindow)

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

PageReceived PROCEDURE,VIRTUAL

Before Parent Call

    IF WebClient.PageLen <= 0
      MyText = ''
    ELSIF WebClient.PageLen < Size(MyText)
      MyText = SUB(WebClient.Page,WebClient.HeaderLen,WebClient.PageLen-WebClient.HeaderLen+1)
    ELSE
      MyText = WebClient.Page [WebClient.HeaderLen : SIZE(MyText)-WebClient.HeaderLen+1]
    .
    POST(EVENT:CloseWindow)

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Window Events - Open Window

        WebClient.SetAllHeadersDefault()
        WebClient.CanUseProxy              = 1
        WebClient.HeaderOnly               = 0
        WebClient.AsyncOpenUse             = 1
        WebClient.AsyncOpenTimeOut         = 1200        !12 seconds
        WebClient.InActiveTimeout          = 2000        !20 seconds
        WebClient.ContentType              = 'application/x-www-form-urlencoded'
        WebClient.AcceptEncoding           = ''
        WebClient.ProxyConnectionKeepAlive = 0
        WebClient.ConnectionKeepAlive      = 0
     
        WebClient.ContentLength = LEN(CLIP(lPost))
     
        WebClient.Post(CLIP(lURL),CLIP(lPost))

[attachment deleted by admin]
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11