Thursday, June 12, 2014

Recaptcha

If your project requires CAPTCHA functionality, I highly recommend Recaptcha.  Recaptcha is a free service offered by Google that serves up CAPTCHA functionality.  First, you need to sign up here.  Assuming you've got a google id and are signed in, all you need to provide is the domain where you will be using recaptcha.  Google will provide you a public and private key that will be used by the recaptcha control.

For ASP.NET, you just need to download the recaptcha dll and reference it in your project.  Then put this at the top of the page where the CAPTCHA functionality is needed:

<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>

This snippet will render the CAPTCHA control itself:

                    <recaptcha:RecaptchaControl
                        ID="recaptcha"
                        runat="server"
                        Theme="white"
                        PublicKey="Provided By Google"
                        PrivateKey="Provided By Google"
                    />


And finally, this code will check to make sure the correct code was entered. This assumes you have a ValidationSummary control on your page.

        If Page.IsValid = False Then
            Return
        End If

No comments:

Post a Comment