How to use reCaptcha with CreateUserWizard In ASP.Net

I was working on using CreateUserWizard ASP.Net control on my web site to allow users to create their account for authorized and authenticated access to certain access of sites. One of the problems you face on the web sites is that spammers tend to run bots to create accounts on sites using direct HTTP requests and things like that. One of the ways to fight this is the use of some CAPTCHA control on the pages. Yes, there are some hackers who claim to bypass some of these counter measures. But still it protects you from about 80% or so of these spam bots.

So one of things you can do is to add ASP.Net plugin for reCaptcha control in template for CreateUserWizard control. There are few issues that I ran into when I tried to integrate into my page. So here are some of the things you can learn from my experience to integrate reCaptch in ASP.Net.

  • There seems to be a validation bug in older version of reCaptcha control plugin. So I had to download the latest source code from google SVN and recompile it to use in my ASP.Net web site. The problem I was running into with bugged plugin was that Postback was not getting fired. After I will click on Create button, the page will just not fire event handler to postback the page. Once I replaced it with recompiled version of reCaptch control, the page worked fine.

  • In the post back event handler, add the following code to validate reCaptcha challenge. This will provide you server side validation of the control. I added following code to my event handler.

    protected void RegisterUser_CreatingUser(object sender, LoginCancelEventArgs e)
    {
      var captcha = 
       (Recaptcha.RecaptchaControl)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("recaptchaCtl");
      if (null == captcha)
      {
        e.Cancel = true;
        return;
      }
      captcha.Validate();
      if (!captcha.IsValid)
      {
        //TODO: Display validation message.
        e.Cancel = true;
        return;
      }
      e.Cancel = false;
    }
    

Search

Social

Weather

24.5 °C / 76.1 °F

weather conditions Haze

Monthly Posts

Blog Tags