How To Add BotDetect CAPTCHA Protection to Classic ASP Forms (BotDetect v3.0; deprecated)
First Time Here?
Check the BotDetect Developer Crash Course for key integration steps.
Protecting your ASP forms with BotDetect ASP Captcha component requires a few steps, outlined on this page. Displaying the Captcha challenge can be as simple as:
<% ' Adding BotDetect CAPTCHA to the page Dim SampleCaptcha : Set SampleCaptcha = (New Captcha)( "SampleCaptcha") SampleCaptcha.UserInputID = "CaptchaCode" Response.Write SampleCaptcha.Html %>and checking user input when the form is submitted:
Dim isHuman : isHuman = SampleCaptcha.Validate()
You can also see how BotDetect Captcha protection has been added to various kinds of ASP forms and projects by running the BotDetect Captcha ASP integration code samples coming with the BotDetect installation. You can also reuse the sample project source code that fits your requirements.
CAPTCHA Integration Steps
To add BotDetect Captcha protection to an ASP Classic website:
- Include BotDetect files in the ASP application
- Display Captcha protection on the ASP form
- Validate Captcha user input during ASP form submission
Include BotDetect Files in the ASP Application
BotDetect Captcha can simply be included in ASP applications by copying the Captcha library files from the BotDetect ASP installation folder.
You will need to copy the following to your ASP application's root folder:
- the
BotDetect.asp
file from:C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp\ CaptchaLibrary\BotDetect.asp
- the whole
BotDetect
folder (containing 13 files in total) from:C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp\ CaptchaLibrary\BotDetect
We'll explain the details of individual Captcha library files later, and focus on the simplest way to use them for now.
Display Captcha Protection on the ASP Form
We'll assume you already have a form which can be posted (<form method="post" ...
), with other fields in place.
First, include the BotDetect Captcha library in the ASP form header, just before the closing <head>
tag:
<!-- #include file ="BotDetect.asp" --> </head>
Including the library in the page header automatically includes the BotDetect Captcha layout spreadsheet.
To display the Captcha test on your form, you will need the following Html elements:
- A textbox for the Captcha code user input, with a label displaying Captcha instructions
- The Captcha markup including the image, sound and reload icons etc., which will be generated by the Captcha library
<label for="CaptchaCode">Retype the characters from the picture: </label> <% ' Adding BotDetect CAPTCHA to the page Dim SampleCaptcha : Set SampleCaptcha = (New Captcha)("SampleCaptcha") SampleCaptcha.UserInputID = "CaptchaCode" Response.Write SampleCaptcha.Html %> <input name="CaptchaCode" id="CaptchaCode" type="text" />
The VbScript code above creates a new instance of the Captcha
class defined by the BotDetect ASP Captcha library, tells it which textbox is used to input Captcha codes, and calls the Html
subroutine to generate all needed BotDetect Html elements.
When you open your form in a browser, the above declarations should render as:
If you are adding Captcha protection to multiple ASP forms in the same application, you should take care to give each one a unique name (e.g. "RegistrationCaptcha", "CommentCaptcha", ...) in the Captcha
object constructor.
Validate Captcha User Input During ASP Form Submission
Since we want to ensure only real human users can perform a certain action (e.g. account registration or comment submission), we also have to add Captcha validation code which will process form submissions, and only allow certain actions if Captcha validation succeeds.
Form Has No Action
In the simplest case (when the form posts to itself, i.e. theaction
attribute is not set), you will process form submissions on the form itself:
<% If Request.ServerVariables("REQUEST_METHOD") = "POST" Then ' CAPTCHA user input validation Dim isHuman : isHuman = SampleCaptcha.Validate() If Not isHuman Then ' CAPTCHA validation failed, show error message Response.Write "Incorrect Captcha code" Else ' CAPTCHA validation passed, perform protected action ' TODO End If End If %>
The above code is very simple:
- The
If Request.ServerVariables("REQUEST_METHOD") = "POST"
line ensures the code only runs when the form is submitted - The
Dim isHuman : isHuman = SampleCaptcha.Validate()
line calls theValidate()
function of theCaptcha
object, which returnsTrue
if the submitted Captcha code matches the one used for Captcha image generation, orFalse
otherwise - Depending on the Captcha validation result, we either show a simple error message, or proceed with form submission
This approach is shown in the BotDetect basic ASP integration code sample included in the BotDetect installation.
Separate Form Processing Action
If your form posts to a separate .asp
file, you can use the same Captcha validation code, you just have to create a Captcha
object instance with the same name as the one used on the form first:
' Captcha validation Dim SampleCaptcha : Set SampleCaptcha = (New Captcha)("SampleCaptcha") SampleCaptcha.UserInputID = "CaptchaCode" Dim isHuman : isHuman = SampleCaptcha.Validate() If Not isHuman Response.Redirect "Default.asp" & "?captchaValid=False" End If ' TODO: continue with form submission
In this case, if the correct Captcha code wasn't submitted, we redirect the user back to the original form (adding a simple querystring for easier error reporting). You can also integrate the isHuman
result with other form validation code, depending on your overall form validation approach.
This approach is shown in the BotDetect ASP form integration code sample included in the BotDetect installation.
Please Note
The information on this page is out of date and applies to a deprecated version of BotDetect™ CAPTCHA (v3.0).
An up-to-date equivalent page for the latest BotDetect Captcha release (v4) is BotDetect v4 Captcha documentation index.
General information about the major improvements in the current BotDetect release can be found at the What's New in BotDetect v4.0 page.
Current BotDetect Versions
-
BotDetect ASP.NET CAPTCHA
2019-07-22v4.4.2 -
BotDetect Java CAPTCHA
2019-07-22v4.0.Beta3.7 -
BotDetect PHP CAPTCHA
2019-07-22v4.2.5