ASP Classic CAPTCHA Randomization VBScript Code Sample (BotDetect v3.0; deprecated)

The ASP Classic Captcha randomization code sample shows how to easily randomize various BotDetect CAPTCHA Captcha control parameters, beyond the basic image and sound style randomization used by default.

Randomly using different CAPTCHA image and sound generation algorithms and other parameter values (such as code length and style) can significantly improve the CAPTCHA security.

This is the recommended approach to Captcha property setting, since it takes full advantage of the 60 CAPTCHA image and 10 CAPTCHA sound generation algorithms shipped with BotDetect, as well as built-in randomization features.

Setting Captcha control properties in the BotDetect/CaptchaConfig.asp file also reduces the amount of Session State used by the control.

Installed Location

By default, the Classic ASP basic Captcha code sample is installed at:
C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp\WebApp\CaptchaRandomizationSample

You can also run it from the BotDetect Start Menu:
Programs > Lanapsoft > BotDetect 3 CAPTCHA Component > ASP > Web Applications > Run


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 

<html xmlns="" >
  <title>BotDetect ASP CAPTCHA Randomization Sample</title>
  <link type="text/css" rel="Stylesheet" href="StyleSheet.css" />
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <!-- #include file ="BotDetect.asp" -->
  <form method="post" action="" id="form1">

    <h1>BotDetect ASP CAPTCHA Randomization Sample</h1>
      <legend>ASP CAPTCHA validation</legend>
      <label for="CaptchaCode">Retype the characters from the picture:
      <% ' Adding BotDetect CAPTCHA to the page 
        Dim SampleCaptcha : Set SampleCaptcha = (New Captcha)("SampleCaptcha")
        SampleCaptcha.UserInputID = "CaptchaCode"
        Response.Write SampleCaptcha.Html %>
      <div class="validationDiv">
        <input name="CaptchaCode" type="text" id="CaptchaCode" />
        <input type="submit" name="ValidateCaptchaButton" 
        value="Validate" id="ValidateCaptchaButton" />
        <% ' CAPTCHA user input validation (only if the form was 
          If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
            Dim isHuman : isHuman = SampleCaptcha.Validate()
            If Not isHuman Then 
              ' CAPTCHA validation failed, show error message
              Response.Write "<span class=""incorrect"">Incorrect code
              ' CAPTCHA validation passed, perform protected action
              Response.Write "<span class=""correct"">Correct code
            End If 
          End If


The form follows the basic procedure for adding Captcha protection to ASP forms.



' Captcha code configuration
' ---------------------------------------------------------------------------
' code length randomization
LBD_Configuration_CodeLength = LBD_RandomFromRange(3, 5)

' Captcha code style randomization, option 1: randomly use all possible code styles
'LBD_Configuration_CodeStyle = LBD_RandomCodeStyle()

' Captcha code style randomization, option 2: randomly choose from the given 
' set of code styles
'Dim codeStyleNames(2)
'codeStyleNames(0) = "Alpha"
'codeStyleNames(1) = "Numeric"
'LBD_Configuration_CodeStyle = LBD_RandomCodeStyleFrom(codeStyleNames)

' Captcha code style randomization, option 3: dependent on code length
Select Case LBD_Configuration_CodeLength
    Case 3
        LBD_Configuration_CodeStyle = LBD_CodeStyles("Alphanumeric")
    Case 4
        LBD_Configuration_CodeStyle = LBD_CodeStyles("Alpha")
    Case 5
        LBD_Configuration_CodeStyle = LBD_CodeStyles("Numeric")
End Select

LBD_Configuration_CodeTimeout = 1200
LBD_Configuration_Locale = "en-US"
LBD_Configuration_CustomCharset = ""
LBD_Configuration_BannedSequences = ""

' Captcha image configuration
' ---------------------------------------------------------------------------
' image style randomization
Dim imageStyleNames(8)
imageStyleNames(0) = "Lego"
imageStyleNames(1) = "MeltingHeat"
imageStyleNames(2) = "Ghostly"
imageStyleNames(3) = "Fingerprints"
imageStyleNames(4) = "Graffiti2"
imageStyleNames(5) = "Bullets2"
imageStyleNames(6) = "CaughtInTheNet2"
imageStyleNames(7) = "Collage"
imageStyleNames(8) = "Chalkboard"
LBD_Configuration_ImageStyle = LBD_RandomImageStyleFrom(imageStyleNames)

LBD_Configuration_ImageWidth = 250
LBD_Configuration_ImageHeight = 50
LBD_Configuration_ImageFormat = LBD_ImageFormats("JPEG")
LBD_Configuration_CustomDarkColor = ""
LBD_Configuration_CustomLightColor = ""
LBD_Configuration_ImageTooltip = "CAPTCHA"
LBD_Configuration_HelpLinkEnabled = True
LBD_Configuration_HelpLinkMode = LBD_HelpLinkModes("Image")
LBD_Configuration_HelpLinkUrl = ""
LBD_Configuration_HelpLinkText = ""

' Captcha sound configuration
' ---------------------------------------------------------------------------
LBD_Configuration_SoundEnabled = True

' sound style randomization
Dim soundStyleNames(2)
soundStyleNames(0) = "Dispatch"
soundStyleNames(1) = "RedAlert"
soundStyleNames(2) = "Synth"
LBD_Configuration_SoundStyle = LBD_RandomSoundStyleFrom(soundStyleNames)

LBD_Configuration_SoundFormat = LBD_SoundFormats("WavPcm16bit8kHzMono")
LBD_Configuration_SoundTooltip = "Speak the CAPTCHA code"
LBD_Configuration_SoundIconUrl = "BotDetect/SoundIcon.gif"
LBD_Configuration_SoundPackageFolder = "C:\Program Files\Lanapsoft\BotDetect 3 
  CAPTCHA Component\Asp\Redistribute\BotDetectSounds"
LBD_Configuration_WarnAboutMissingSoundPackages = True
LBD_Configuration_SoundStartDelay = 0
LBD_Configuration_SoundRegenerationMode = LBD_SoundRegenerationModes("Limited")

' Captcha reload configuration
' ---------------------------------------------------------------------------
LBD_Configuration_ReloadEnabled = True
LBD_Configuration_ReloadTooltip = "Change the CAPTCHA code"
LBD_Configuration_ReloadIconUrl = "BotDetect/ReloadIcon.gif"
LBD_Configuration_AutoReloadExpiredCaptchas = True
LBD_Configuration_AutoReloadTimeout = 7200

' Captcha user input  configuration
' ---------------------------------------------------------------------------
LBD_Configuration_AutoFocusInput = True
LBD_Configuration_AutoClearInput = True
LBD_Configuration_AutoUppercaseInput = True

' Captcha remote script configuration
' ---------------------------------------------------------------------------
LBD_Configuration_RemoteScriptEnabled = True

' Captcha persistence configuration
' ---------------------------------------------------------------------------
Dim LBD_Persistence : Set LBD_Persistence = Session
LBD_Configuration_UseApplicationFallback = True


The ASP Captcha library configuration file defines base Captcha settings for the sample, including Captcha randomization rules.

Randomized settings use the Captcha randomization functions and general helper functions included in the Captcha library.

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.