I recently had a requirement to implement a CAPTCHA for one of our contact forms to minimize spam.
After much research and consideration I decided to use reCAPTCHA and the reCAPTCHA ASP.NET library.
Step 1 - Create a free account
http://www.google.com/recaptcha
Step 2 - Download the reCAPTCHA ASP.NET library
http://code.google.com/apis/recaptcha/docs/aspnet.html
I'm using the .Net control but as you'll see it has plugins for several platforms.
To get it working was just a matter of referencing the library in my project, dropping the control on my page and referencing the public/private keys generated in step 1.
After much research and consideration I decided to use reCAPTCHA and the reCAPTCHA ASP.NET library.
Step 1 - Create a free account
http://www.google.com/recaptcha
Step 2 - Download the reCAPTCHA ASP.NET library
http://code.google.com/apis/recaptcha/docs/aspnet.html
I'm using the .Net control but as you'll see it has plugins for several platforms.
To get it working was just a matter of referencing the library in my project, dropping the control on my page and referencing the public/private keys generated in step 1.
12 comments:
Niall N
I can't find the aspnet library anywhere! It is not available in the google downloads!?! Any ideas / help?!?!
October 18, 2011 at 12:15 PM
Matt Pavey
Looks like their link is not quite right, so I had to take out the search criteria and then it worked fine. Try this direct link:
http://code.google.com/p/recaptcha/downloads/list?can=2&q=&colspec=Filename+Summary+Uploaded+ReleaseDate+Size+DownloadCount
October 18, 2011 at 12:21 PM
Niall N
yeah, but which one do I need for aspx ?
October 18, 2011 at 12:26 PM
Matt Pavey
I am using the current release, which is "reCAPTCHA .NET Library v1.0.5.0 Binary Only"
October 18, 2011 at 12:28 PM
Niall N
ok..you're going to be sorry now you replied back so quickly!! :)
Can you give me more precise instructions on how to actually get the thing to work and add the catpcha quetion to my form!?!
I'm a real novice here and this has being driving me crazy all day!!
October 18, 2011 at 12:34 PM
Matt Pavey
The first thing you need to do is add a reference in your web project to the Recaptcha.dll that you extracted from the download.
Then you will want to register the assembly on the .aspx page.
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
Next place the control on your page wherever you want it to show up.
< recaptcha:RecaptchaControl ID="recaptcha" PublicKey="YourPublicKey" PrivateKey="YourPrivateKey" Theme="white" runat="server" />
If you don't have a public/private key yet you can get one from http://www.google.com/recaptcha
Then use a button (or whichever control you want) to initiate your postback.
< asp:Button id="btnSubmit" Text="Submit" runat="server" />
Then have some kind of postback event in your code-behind to validate the postback.
Private Sub btnSubmit_Click(sender As Object, e As System.EventArgs) Handles btnSubmit.Click
'validate captcha
If Not Page.IsValid Then
'recaptcha phrase entered was not correct
Return
End If
'validation successful
End Sub
Hope that helps, good luck!
October 18, 2011 at 12:48 PM
Niall N
Ok, I got most of that, but how do I reference the .dll from the .aspx file?
October 18, 2011 at 12:51 PM
Matt Pavey
If you are using Visual Studio you can right click on your web project in the Solution Explorer and choose "Add Reference..." and then browse to the Recaptcha.dll.
Then all you need to do is register the control on your .aspx page.
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
October 18, 2011 at 12:55 PM
Niall N
I'm building the site using DreamWeaver...if that means anything?
October 18, 2011 at 12:55 PM
Matt Pavey
You can probably just copy the Recaptcha.dll into your /bin folder then.
October 18, 2011 at 12:57 PM
Niall N
ok, thanks Matt...much appreciated!!
October 18, 2011 at 1:00 PM
Matt Pavey
No problem!
October 18, 2011 at 1:00 PM