ASP.NET

Confident Captcha - ASP.NET Library

Download ASP.NET Library

The Confident Captcha ASP.NET Library provides an easy and secure way to use Confident Captcha on your web site, this helps reduce the amount of spam produced by bots. The ASP.NET library makes calls the the API directly while providing the developer easy to use functions for an easy and secure deployment.

In order to use the ASP.NET library for Confident Captcha, you must download the ASP.NET library and unzip it.

Quick-start

* Skip this step if you've already added a site to your dashboard account


In other to obtain the credentials you will need to use Confident Captcha, register for a free account at http://www.confidenttechnologies.com/Get_Confident_CAPTCHA.  Once you have filled out that form you will recieve an activation email.  Once you click to activate your account, you will be logged in.  Once you are at the site follow the steps below to obtain your credentials.

  1. Click Add a new site.
  2. In the text box next to Site Name:  type in the name of your site then click Add site.
  3. Click on the Overview link, here you will find the credentials you will need for the Configuration of your site.

After you've obtained your API credentials, below are the basic steps to getting Confident Captcha up and running on your site.

Configuration


First open the settings.xml file located in the Configurations subdirectory of the CaptchaSite folder. Then with the information from the site overview page.  (Go to your dashboard, then click overview) change the following values to those listed on that page.

  • customer_id
  • site_id
  • api_username
  • api_password

Your settings.xml file should look similar to this.

<configuration>
    <credentials>
        <customer_id>xXXxxxXx</customer_id>
        <site_id>SampleSite</site_id>
        <api_username>XxXxxxX0xxXx0x0x0xXx0XX0xxXXxxX0xXx0XxXX</api_username>
        <api_password>XxXxxxX0xxXx0x0x0xXx0XX0xxXXxxX0xXx0XxXX</api_password>
    </credentials>
</configuration>

Save your settings file with the updated values.

For a complete list of the customizations you can perform, please refer to the Confident Captcha Configuration page.

The options you can configure are:

  • width
  • height
  • captcha_length
  • logo
  • billboard
  • ajax_verify
  • and others!

Displaying the Confident Captcha.


sample_after_form.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="ConfidentTechnologies.Captcha"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head id="Head1" runat="server">
        <script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <%
                //Instantiate a Confident CAPTCHA client
                ConfidentCaptchaClient client = new ConfidentCaptchaClient("Configurations/settings.xml");
                //Request a new CAPTCHA
                string createCaptchaResponse = client.createCaptcha();
            %>
            <%= createCaptchaResponse %>
            <asp:button id="Button2" text="Submit" postbackurl="sample_after_result.aspx" runat="Server"></asp:button>
        </form>
    </body>
</html>

Notice that the asp:button postbackurl attribute is sample_after_result.aspx.  You will need to make sure the sample_after_result.aspx file is located in the same directory in order for the form to go to that page upon clicking the submit button.

Verifying the Confident Captcha.


Sample_After_Form.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="ConfidentTechnologies.Captcha"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head id="Head1" runat="server">
        <title>Post: Receiver</title>
    </head>
    <body>
    <%
        //Instantiate a Confident CAPTCHA client
        ConfidentCaptchaClient client = new ConfidentCaptchaClient("Configurations/settings.xml");
        //Check to see if the user solved the captcha correctly and react accordingly
        ConfidentTechnologies.Captcha.CheckCaptchaResponse checkCaptchaResponse = client.checkCaptcha(Request.Params, null, null, null);

        if (checkCaptchaResponse != null && checkCaptchaResponse.wasCaptchaSolved())
        {
            //This code gets executed if the Captcha was solved correctly
            alertMessage =
                "\"Captcha solved correctly.\"";
        }
        else
        {
            //This code gets executed if the Captcha was solved incorrectly
            alertMessage = "\"CAPTCHA failed -- please try again.\"";
        }
    %>
    <h3>Captcha Solution Result:</h3>
    <%= createCaptchaResponse %>
    </body>
</html>

Notes on the Server side code:

  • the checkCaptcha method returns an object to handle whether the user has completed the captcha solution.
  • If checkCaptchaResponse.wasCaptchaSolved() is true the user has successfully solved the captcha and the page should be displayed.
  • If checkCaptchaResponse.wasCaptchaSolved() is false the user has not successfully solved the captcha and should try again.

Deploying the .NET library


You will need to publish/compile the project ( in the build menu ) using Visual Studio and then add the compiled directory to the location on your website where you're form resides. The above code shows a minimal amount of code the form and submit pages will need to have in order for Confident Captcha to work correctly.

Be sure to include jQuery 1.7.1, in the <head> section of any page you wish to display Confident Captcha.

This version of the plugin also requires the use of Json. Your project will need to reference Newtonsoft.Json in order for it to work with this plugin. Here's how you can do that with Visual Studio 2012:

  1. Right click the Captcha folder and select "Manage NuGet Packages..."
  2. Enter "json" in the search bar and Json.NET should pop up as an installable package
  3. Click Install on the Json.Net package to add it to the Captcha project

Once those changes are saved and uploaded to your website or tested locally you will have successfully implemented Confident Captcha!

.NET Notes


The latest version of the .NET library is 20130514_DOTNET, released May 14th, 2013.

A .NET or Mono runtime environment, version 3.5 or later, is required.

If you run into any problems with this plugin or general questions, please contact us