Casual ideas for web development

Help

Image-Based Bot Detector is a variant of image-based CAPTCHAs that uses human ability to recognize a distorted region on the image he never seen before.

In order to use it you have to set TemplateImageFolder property to relative virtual path of the template images folder - for example, "~/templates" and to add registration of HttpHandler in web.config.

<httpHandlers>
  <add verb="GET" path="ImageBasedBotDetector.ashx"          
            type="Marss.Web.UI.Controls.ImageBasedBotDetector, Marss.Web"/>
</httpHandlers>

There are 3 types of predefined distortion (Stretched, Random, Volute) and user-defined (Custom) distortion. In order to use predefined distortion it needs to set DistortionType property. User-defined distortion can be used in derived classes with overriden DrawCustom method.

If you want to use template images that are placed elsewhere then a subfolder of your web application - for example, from database - you have to override GetTemplateImage method.

To check whether user passed the test IsValid property is used. Also user can be locked after a predefined number of unsuccessful attempts to pass the test (FailedAttemptsBeforeLocking property, default value is 5).

Requires .NET Framework 2.0

Working example of Image-Based Bot Detector.
Working example of the control derived from Image-Based Bot Detector.
Download

Public properties
TemplateImageFolder Gets or sets template image folder.
FailedAttemptsBeforeLocking Gets or sets the number of unsuccessful attempts before locking.
IsValid Gets result of test passing.
IsLocked Gets or sets value indicating where user is locked.
DistortionType Gets or sets distortion type. Available types:
  • Stretched - image within distorted area is stretched.
  • Random - points within distorted area is mixed in a random way.
  • Volute - image within distorted area is volute.
  • Custom - custom distortion. Have to be used together with overriden DrawCustom method.
Public events
Locked Occurs when detector has been locked because of exceeding the failed attempts limit.
public event EventHandler Locked
Protected virtual methods
GetTemplateImage Gets template image.
protected virtual System.Drawing.Image GetTemplateImage()
See example of usage.
DrawCustom Distorts specified rectangle of image in a user defined way. Have to be used coupled with DistortionType=Custom
protected virtual void DrawCustom(System.Drawing.Bitmap bitmap, System.Drawing.Image img, Rectangle distortedRectangle)
where
bitmap - the output image,
img - the template (input) image,
distortedRectangle - area on the image to be distorted.

About this blog

This is a personal blog of Mykola Tarasyuk, a web developer from Ukraine. It includes articles about ASP.Net, C#, Javascript and anything else that tickles the fancy of the author ...

Top 6 of 2009


All Articles

Locations of visitors to this page
Copyright © Mykola Tarasyuk, 2007-2010