BotDetect ASP.NET CAPTCHA Core API Reference

While the BotDetect.Web members are used for Captcha control functionality within a Web context, the root BotDetect ASP.NET Captcha namespace contains members related to general Captcha functionality, independent of the context it's used for.

BotDetect.CaptchaBase

A base Captcha object, representing a generic Captcha instance capable of generating Captcha codes, images and sounds + validating user inputs. The Captcha instances tailored for System.Web use all delegate core Captcha functionality to a contained CaptchaBase instance.

Also, if you were for example implementing a Captcha class tailored for Windows Forms applications, you would implement a CaptchaWinFormControl class, which would implement desktop context-specific functionality and delegate Captcha functionality to a contained CaptchaBase instance.

BotDetect.CaptchaBase Class Reference
BotDetect.CaptchaBase public method CaptchaBase
  • string captchaId
Captcha identifier, distinguishing multiple Captcha instances within the system. Each Captcha used in a different location (web page or Windows Form or mobile screen) must have a unique identifier
BotDetect.CaptchaBase public property string CaptchaId Captcha identifier, distinguishing multiple Captcha instances within the system. Can also be accessed through this property, after being initialized in the constructor
BotDetect.CaptchaBase public property int CodeLength Number of characters in randomly generated Captcha codes (answers to Captcha challenges). The default value is random (4-6 characters)
BotDetect.CaptchaBase public property BotDetect.CodeStyle CodeStyle Character types, used to generate random Captcha codes. The default value is Alphanumeric
BotDetect.CaptchaBase public property string DisallowedCodeSubstringsCsv Strings that should never occur in randomly generated Captcha codes. Can be both single characters (allows Captcha character set customization) and sequences of two or more characters (useful for swear words filtering, avoiding particular hard-to-read sequences etc.). The default value is empty (Captcha code filtering is optional)
BotDetect.CaptchaBase public property List<string> DisallowedCodeSubstringsList Strings that should never occur in randomly generated Captcha codes. Can be both single characters (allows Captcha character set customization) and sequences of two or more characters (useful for swear words filtering, avoiding particular hard-to-read sequences etc.). The default value is empty (Captcha code filtering is optional)
BotDetect.CaptchaBase public property int CodeTimeout The time period after random Captcha code generation during which Captcha challenges based on it can be solved: when it expires, even correct inputs will be considered as invalid submissions. The default value is 1200 seconds (20 minutes)
BotDetect.CaptchaBase public property BotDetect.ImageStyle ImageStyle Image style, The BotDetect drawing algorithm used to render Captcha codes in image Captcha challenges. The default value is random (an image style is chosen from all available values for each Captcha image generated)
BotDetect.CaptchaBase public property System.Drawing.Size ImageSize Size of Captcha image challenges generated. The default value is 250 x 50 pixels
BotDetect.CaptchaBase public property BotDetect.ImageFormat ImageFormat Image format in which Captcha images will be generated and sent to the client. The default value is Jpeg
BotDetect.CaptchaBase public property System.Drawing.Color CustomDarkColor Optional custom dark color point, modifies the color palette used for Captcha image drawing
BotDetect.CaptchaBase public property System.Drawing.Color CustomLightColor Optional custom light color point, modifies the color palette used for Captcha image drawing
BotDetect.CaptchaBase public property bool SoundEnabled Is Captcha sound enabled. The default value is true
BotDetect.CaptchaBase public property BotDetect.SoundStyle SoundStyle The BotDetect audio generation algorithm used to pronounce Captcha codes in sound Captcha challenges. The default value is random (a sound style is chosen from all available values for each Captcha sound generated)
BotDetect.CaptchaBase public property BotDetect.SoundFormat SoundFormat Audio format Captcha sounds will be generated and sent to the client. The default value is WavPcm16bit8kHzMono
BotDetect.CaptchaBase public property BotDetect.SoundRegenerationMode SoundRegenerationMode

How will multiple consecutive requests for audio Captcha with the same Captcha code ('sound regeneration') be handled by BotDetect - a tradeoff of security, usability, and storage requirements. The default value is Limited

BotDetect.CaptchaBase public property string Locale Captcha locale string, determining the exact character set used for random Captcha code generation and the pronunciation language used for sound Captcha generation. The default value is en-US
BotDetect.CaptchaBase public property bool HelpLinkEnabled Will Captcha markup include a link to a Captcha help page providing Captcha instructions and explanations for form users. The default value is true
BotDetect.CaptchaBase public property BotDetect.HelpLinkMode HelpLinkMode How will the Captcha help link be displayed. The default value is Text
BotDetect.CaptchaBase public property readonly string InstanceId Globally unique identifier of the current CaptchaBase object instance
BotDetect.CaptchaBase public property static readonly System.Text. RegularExpressions.Regex ValidCaptchaId The global regular expression object used to validate CaptchaId values and ensure they match the persistence medium key limitations
BotDetect.CaptchaBase public method string GetCode
  • string instanceId
  • BotDetect. CodeGenerationPurpose purpose
Generates a random Captcha code for the given purpose, using settings stored in instance data belonging to the specified instanceId
BotDetect.CaptchaBase public method System.IO.MemoryStream GetImage
  • string instanceId
Generates a Captcha image, using settings stored in instance data belonging to the specified instanceId
BotDetect.CaptchaBase public method System.IO.MemoryStream GetSound
  • string instanceId
Generates a Captcha sound, using settings stored in instance data belonging to the specified instanceId
BotDetect.CaptchaBase public method bool Validate
  • string userInput
  • string instanceId
  • BotDetect. ValidationAttemptOrigin origin
Compares the user input to the Captcha code stored for the given instanceId, using validation rules specified for the current ValidationAttemptOrigin
BotDetect.CaptchaBase public method static void RegisterGenerating CaptchaCodeHandler
  • string captchaId
  • EventHandler< BotDetect.GeneratingCaptcha CodeEventArgs> handler
Propagate GeneratingCaptchaCode event handlers registered in delegating classes to the global event delegate
BotDetect.CaptchaBase public method static void RegisterGenerated CaptchaCodeHandler
  • string captchaId
  • EventHandler< BotDetect.GeneratedCaptcha CodeEventArgs> handler
Propagate GeneratedCaptchaCode event handlers registered in delegating classes to the global event delegate
BotDetect.CaptchaBase public method static void RegisterGenerating CaptchaImageHandler
  • string captchaId
  • EventHandler< BotDetect.GeneratingCaptcha ImageEventArgs> handler
Propagate GeneratingCaptchaImage event handlers registered in delegating classes to the global event delegate
BotDetect.CaptchaBase public method static void RegisterGenerated CaptchaImageHandler
  • string captchaId
  • EventHandler< BotDetect.GeneratedCaptcha ImageEventArgs> handler
Propagate GeneratedCaptchaImage event handlers registered in delegating classes to the global event delegate
BotDetect.CaptchaBase public method static void RegisterGenerating CaptchaSoundHandler
  • string captchaId
  • EventHandler< BotDetect.GeneratingCaptcha SoundEventArgs> handler
Propagate GeneratingCaptchaSound event handlers registered in delegating classes to the global event delegate
BotDetect.CaptchaBase public method static void RegisterGenerated CaptchaSoundHandler
  • string captchaId
  • EventHandler< BotDetect.GeneratedCaptcha SoundEventArgs> handler
Propagate GeneratedCaptchaSound event handlers registered in delegating classes to the global event delegate
BotDetect.CaptchaBase public method static void RegisterValidating UserInputHandler
  • string captchaId
  • EventHandler< BotDetect.ValidatingUser InputEventArgs> handler
Propagate ValidatingUserInput event handlers registered in delegating classes to the global event delegate
BotDetect.CaptchaBase public method static void RegisterValidated UserInputHandler
  • string captchaId
  • EventHandler< BotDetect.ValidatedUser InputEventArgs> handler
Propagate ValidatedUserInput event handlers registered in delegating classes to the global event delegate

BotDetect.Code

Represents a single randomly generated Captcha code.

BotDetect.Code Class Reference
BotDetect.Code public method Code
  • string captchaCode
The constructor takes the freshly generated random Captcha code that will be contained in the object
BotDetect.Code public property bool IsUsedForSoundGeneration Has the Captcha code been used to generate a Captcha sound
BotDetect.Code public property bool IsUsedForImageGeneration Has the Captcha code been used to generate a Captcha image
BotDetect.Code public property readonly string CaptchaCode The random Captcha code contained in the object
BotDetect.Code public property readonly System.DateTime GenerationTime When was the random Captcha code generated
BotDetect.Code public property readonly int ElapsedSeconds How many seconds have elapsed since the random Captcha code was generated

BotDetect.CodeCollection

Represents a collection of Captcha codes generated for a particular Captcha instance (identified by captchaId) in the current applications.

Implements

System.Collections.Generic.IEnumerable<BotDetect.Code>, System.Collections.IEnumerable

BotDetect.CodeCollection Class Reference
BotDetect.CodeCollection public method CodeCollection The default CodeCollection constructor takes no arguments
BotDetect.CodeCollection public method public IEnumerator <BotDetect.Code> GetEnumerator Allows enumerating the contained Code instances
BotDetect.CodeCollection public method string GetCode
  • string instanceId
  • BotDetect. CodeGenerationPurpose purpose
  • BotDetect.CodeStyle codeStyle
  • int codeLength
  • int codeTimeout
Given the Captcha instance identifier and Captcha code purpose, returns an existing Captcha code if a valid one exists, or creates a new one automatically
BotDetect.CodeCollection public method void SaveCode
  • string instanceId
  • BotDetect.Code code
  • int timeLimit
Stores a Code object in the collection
BotDetect.CodeCollection public method bool Validate
  • string userInput
  • string instanceId
  • BotDetect. ValidationAttemptOrigin origin
Compares the user input to stored values matching the criteria
BotDetect.CodeCollection public property readonly int Count How many Code instances are contained in the collection

BotDetect.DisallowedCodeSubstrings

Represents a collection of disallowed code substrings that will be excluded from all randomly generated Captcha codes.

BotDetect.DisallowedCodeSubstrings Class Reference
BotDetect.DisallowedCodeSubstrings public method DisallowedCodeSubstrings
  • System.Collections. Generic.List<string> input
The default DisallowedCodeSubstrings constructor takes a list of disallowed substrings as simple strings
BotDetect.BannedCharacterSequences public method BotDetect.DisallowedCodeSubstrings FromList
  • System.Collections. Generic.List<string> disallowedCodeSubstringsList
BotDetect.BannedCharacterSequences public method BotDetect.DisallowedCodeSubstrings FromCsv
  • string disallowedCodeSubstringsCsv
BotDetect.BannedCharacterSequences public method BotDetect.Set<int> GetDisallowedCharacters Returns the full set of individual disallowed Unicode code points (which can also be specified this way)
BotDetect.BannedCharacterSequences public method BotDetect.Set<int> GetDisallowedCharacters
  • int length
  • string startingWith
Returns the set of possible Unicode code points that must not be used to randomly choose the next character, given the current already generated character substring

BotDetect.CaptchaRandomization

A helper class used for easy randomization of Captcha parameters.

BotDetect.CaptchaRandomization Class Reference
BotDetect.CaptchaRandomization public method static int GetRandomCodeLength Returns a random Captcha code length, using default code length bounds
BotDetect.CaptchaRandomization public method static int GetRandomCodeLength
  • int max
Returns a random Captcha code length, using the default minimal value and the specified maximal value
BotDetect.CaptchaRandomization public method static int GetRandomCodeLength
  • int min
  • int max
Returns a random Captcha code length, using the specified minimal and maximal values
BotDetect.CaptchaRandomization public method static BotDetect.CodeStyle GetRandomCodeStyle
  • params BotDetect.CodeStyle[] usedValues
Returns a random Captcha code style. Selects from all available styles if no parameter is specified, or from the given value set if specified
BotDetect.CaptchaRandomization public method static BotDetect.ImageStyle GetRandomImageStyle
  • params BotDetect.ImageStyle[] usedValues
Returns a random Captcha image style. Selects from all available styles if no parameter is specified, or from the given value set if specified
BotDetect.CaptchaRandomization public method static BotDetect.SoundStyle GetRandomSoundStyle
  • params SoundStyle[] usedValues
Returns a random Captcha sound style. Selects from all available styles if no parameter is specified, or from the given value set if specified

BotDetect.StringHelper

A helper class used for common string operations used by BotDetect code.

BotDetect.StringHelper Class Reference
BotDetect.StringHelper public method static bool HasValue
  • string input
Checks that the suppliedstring is not null, empty, or consists of only whitespace characters
BotDetect.StringHelper public method static string[] CsvToArray
  • string csvInput
Splits the supplied comma-separated input into a string array
BotDetect.StringHelper public method static BotDetect.Set<int> GetCodePoints
  • System.Collections. Specialized.StringCollection chars
Converts the given collection of characters into Unicode code points
BotDetect.StringHelper public method static System.Collections. Specialized.StringCollection ParseCsv
  • string csvInput
Splits the supplied comma-separated input into a character collection
BotDetect.StringHelper public method static string LogFriendly
  • params object[] values
Writes the given input to a log-friendly string
BotDetect.StringHelper public method static string LogFriendly
  • params string[] values
Writes the given input to a log-friendly string
BotDetect.StringHelper public method static string LogFriendly
  • string input
Writes the given input to a log-friendly string
BotDetect.StringHelper public method static string ToString
  • System.DateTime input
Writes the given input to a log-friendly string
BotDetect.StringHelper public method static string ToString
  • object input
Writes the given input to a log-friendly string
BotDetect.StringHelper public method static System.Text.StringBuilder LogFriendlyWrite
  • System.Text.StringBuilder sb
  • params string[] values
Writes the given input to the StringBuilder instance in a log-friendly format