Miraplacid MSCABImage 2.0
MSCABImage is the best cure from nasty posting bots (robots).
These bots create hundreds email accounts on your web-based mail servers and spam from them, fill
your forums with thousands of commercial postings and screw your online polls.
How it works. ABImage Component generates random number and make a hard-to-recognize picture from it.
Your Web Application asks visitor to read the number and type it in a textbox. Human can easily recognize the number,
but there is no way how a bot can do that. As soon as the form will be posted back, application compare the random
number with the number posted by visitor and authorize a human or reject a bot.
The number can be generated by internal random number generator or can be set by the application.
Image can be extra protected from recognition with adding random noise.
|
Component creation
To create component, use the following constructions
- JScript: var obj = Server.CreateObject("Miraplacid.MSCABImage");
- VBScript: set obj = Server.CreateObject("Miraplacid.MSCABImage")
Note:
Component designed for Apartment threading model. Therefore, the best scope of their using is ASP page level scope.
Using components of version 1.2 in Application and Session scopes may cause problems
with your ASP Server (IIS or Chili) productivity.
To learn more about ASP execution scopes, see your ASP Server manual.
Usage example
Let's consider simple HTML form with a few elements
to submit some text to the server. Form protected with ABImage component.
<%@ LANGUAGE=JScript %>
<html>
<head>
<body>
<%
obj = Server.CreateObject("Miraplacid.MSCABImage");
if (!Request.TotalBytes){
Session("number") = obj.Number;
} else {
if (Request.Form("number")==Session("number")){
Response.Write("<B>Form Submitted Successfully</B>");
var fs = Server.CreateObject("Scripting.FileSystemObject");
path = Server.MapPath("images/");
fs.DeleteFile(path+"/"+Session.SessionID+".jpg",true);
Response.End();
} else {
Response.Write("<B><FONT COLOR='red'>Enter the number as it is shown in the box below.");
Response.Write("</FONT></B><BR>");
obj.Number = Session("number");
}
}
%>
<form name="testform" method="post">
Name:<input type="text" name="fullname" value="John Smith"><br>
Password:<input type="password" name="password" value="password"><br>
Email:<input type="text" name="email" value="JohnSmith@server.com"><br>
Enter the number as it is shown in the box below.<br>
<%
var path = Server.MapPath("images/");
obj.SaveToFile(path+"/"+Session.SessionID+".jpg");
%>
<IMG SRC="<%="images/"+Session.SessionID +".jpg"%>" BORDER="1"><br>
<input type="text" name="number"><br>
<input type="submit" Value="Submit"><br>
</form>
</body>
</html>
This page generates HTML form with inserted image for
protection. At first it checks whether form was submitted; if not - it creates a new ABImage
object and stores its number in the Session, if yes - just compares value entered by user
with pre-generated number. Generated image is saved to temporary file by calling SaveToFile
method.
There is no need to initialize Number property of ABImage object.
It initialized automatically with random value during the object creation. You can always change the number and corresponding image
by calling GenerateRnd or by changing value of Number property.
Image size
Default image size is 120x30 pixels. You can change
image size by changing Height property. Image width depends from image
height and length of the number with the following equation:
width = height * digits_in_number / 2
You can obtain width of the image by calling GetWidth method.
Note: Minimal height value is 20 pixels. If you will try to set height value <
20, it will be automatically set to 20. You can change image size using HTML
properties WIDTH and HEIGHT in your IMG tag:
<IMG SRC="image.jpg" HEIGHT="10" WIDTH="25">
Getting resulting images
There are two ways to return generated image from ABImage object: SaveToFile and GetImage methods.
SaveToFile method saves image to file in JPEG format. The only parameter
is file name (with absolute or abstract path to file) to save to.
Note: Please, make sure your script has write permissions for the folder you are going to save the image to.
GetImage method returns SAFEARRAY of BYTES (raw JPEG image data). It can be used, for example, with Response.BinaryWrite method.
For additional information, see imggen.asp example.
Note:
To learn more about Response.BinaryWrite and Visual Basic safe arrays, see your ASP Server manual.
Additional protection from automatic image recognition
You can add extra protection from recognition
by robots to the image using Noise property. If Noise is set to true, generated
image will be filled with noisy random color (grayscale) pixels.
Object reference
| Method |
Parameters |
Return Value |
Description |
| GenerateRnd |
Long length |
Long |
Generates a random number of length digits.
Returns generated number. |
| SaveToFile |
String dst |
None |
Saves image to file named dst in JPEG format. |
| GetImage |
None |
Array |
Returns SAFEARRAY of BYTES (raw JPEG image data). |
| GetWidth |
None |
Long |
Returns current image width in pixels. Image width depends from image height and number of digits. |
| Property |
Type |
Description |
| Number |
String |
Read/Write property. Can be used to export/import base number.
|
| Height |
Long |
Read/Write property. Can be used for image size control. |
| Noise |
Boolean |
Read/Write property. If true - image will have noise, if false - image will be generated without noise. |
|