Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
Available now!
Buy at Amazon US or
Buy at Amazon UK



Articles

1.Windows API reference
2.HTML to WML Converter
3.Webcam streaming in VB.NET
4.Remoting with firewalls
5.RSA from first principles
6.Key & MouseLogger in .NET
7.Networking Resource Kit for .NET
8.Automatic Reboot with .NET
9.XAML Schema
10.Migrating VB6 Winsock to VB.NET
11.Migrating C++ sockets to C#
12.RFC Reference guide
13.Lingua - Localization webservice
14.COM Reference guide
15.WMI Reference guide
16.SQL stored procedures
17.TCP & UDP port reference
18..NET Framework reference
19.Ethernet Type codes
20.IP to country webservice
21.MAC address assignments
22.DLL entry point reference
23.WHOIS server list
24. Turing Numbers
25. Boost SQL performance
26. Progress Bar in ASP.NET
27. OleDb WebService
27. Internet Explorer

Contact us

Turing Numbers - How to prevent automatic submissions and registrations to your website.


Turing numbers are obscured images showing some random text. They can be read by humans easily, but can foil automated tools that submit spam to blogs, perform automated registrations, and such like. They are named after Alan Turing, a british matematician who hypotesized that a computer could be considered aware if a person could not tell whether they were talking to a machine, or another human on a remote terminal.

To give an example - please type in the number below, and press submit.




If you want to use this on your own website, all you need is a little HTML and Javascript knowledge to perform the following steps:

Step 1.

Place an Image tag at the position where you would like to see the turing image, it is 200 x 50 pixels in size. You will need to name this image "turingImage", and you must also link the image to http://network.programming-in.net (otherwise it won't work).

Insert this HTML into the body of your page:
  <a href="http://network.programming-in.net">
   <img name="turingImage" border=0>
  </a>
 

Step 2.

Add a Form tag to your page. It should be named "myForm" and have an onSubmit function like follows
  <form name=myForm onSubmit="return checkTuringImage()">
  </form>
 

Step 3.

Add a text box, and a submit button to the form. In this case I have named the text box txtTuringChallenge.
   <input type="text" name="txtTuringChallenge">
   <br>
   <input type="submit" value="Check Turing Number">  
 

Step 4.

Assuming your form is called myForm, and your text box is called txtTuringChallenge. Then, at the Bottom of your page (before the closing Body tag), add the following piece of javascript:
 <script language="javascript">
  function checkTuringImage()
  {
   if (window.document.myForm.txtTuringChallenge.value==TuringNumber)
   {
	return true;
   }
   else
   {
    alert("Please type in the five digit number into the space provided before proceding");
    return false;
   }
  }
 </script>
 <script language="javascript">   
   var TuringImage = 'turingImage';  
 </script>
 <script src="http://network.programming-in.net/articles/turing.aspx" language="javascript">
 </script>
 
private void Page_Load(object sender, System.EventArgs e) { // Create a CAPTCHA image using the text stored in the Session object. CaptchaImage ci = new CaptchaImage(this.Session["CaptchaImageText"].ToString(), 200, 50, "Century Schoolbook"); // Change the response headers to output a JPEG image. this.Response.Clear(); this.Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format. ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); } /// /// Summary description for CaptchaImage. /// public class CaptchaImage { // Public properties (all read-only). public string Text { get { return this.text; } } public Bitmap Image { get { return this.image; } } public int Width { get { return this.width; } } public int Height { get { return this.height; } } // Internal properties. private string text; private int width; private int height; private string familyName; private Bitmap image; // For generating random numbers. private Random random = new Random(); // ==================================================================== // Initializes a new instance of the CaptchaImage class using the // specified text, width and height. // ==================================================================== public CaptchaImage(string s, int width, int height) { this.text = s; this.SetDimensions(width, height); this.GenerateImage(); } // ==================================================================== // Initializes a new instance of the CaptchaImage class using the // specified text, width, height and font family. // ==================================================================== public CaptchaImage(string s, int width, int height, string familyName) { this.text = s; this.SetDimensions(width, height); this.SetFamilyName(familyName); this.GenerateImage(); } // ==================================================================== // This member overrides Object.Finalize. // ==================================================================== ~CaptchaImage() { Dispose(false); } // ==================================================================== // Releases all resources used by this object. // ==================================================================== public void Dispose() { GC.SuppressFinalize(this); this.Dispose(true); } // ==================================================================== // Custom Dispose method to clean up unmanaged resources. // ==================================================================== protected virtual void Dispose(bool disposing) { if (disposing) // Dispose of the bitmap. this.image.Dispose(); } // ==================================================================== // Sets the image width and height. // ==================================================================== private void SetDimensions(int width, int height) { // Check the width and height. if (width <= 0) throw new ArgumentOutOfRangeException("width", width, "Argument out of range, must be greater than zero."); if (height <= 0) throw new ArgumentOutOfRangeException("height", height, "Argument out of range, must be greater than zero."); this.width = width; this.height = height; } // ==================================================================== // Sets the font used for the image text. // ==================================================================== private void SetFamilyName(string familyName) { // If the named font is not installed, default to a system font. try { Font font = new Font(this.familyName, 12F); this.familyName = familyName; font.Dispose(); } catch (Exception ex) { this.familyName = System.Drawing.FontFamily.GenericSerif.Name; } } // ==================================================================== // Creates the bitmap image. // ==================================================================== private void GenerateImage() { // Create a new 32-bit bitmap image. Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb); // Create a graphics object for drawing. Graphics g = Graphics.FromImage(bitmap); //g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, this.width, this.height); // Fill in the background. HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White); g.FillRectangle(hatchBrush, rect); // Set up the text font. SizeF size; float fontSize = rect.Height + 1; Font font; // Adjust the font size until the text fits within the image. do { fontSize--; font = new Font(this.familyName, fontSize, FontStyle.Bold); size = g.MeasureString(this.text, font); } while (size.Width > rect.Width); // Set up the text format. StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; // Create a path using the text and warp it randomly. GraphicsPath path = new GraphicsPath(); path.AddString(this.text, font.FontFamily, (int) font.Style, font.Size, rect, format); float v = 4F; PointF[] points = { new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v) }; Matrix matrix = new Matrix(); matrix.Translate(0F, 0F); path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); // Draw the text. hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray); g.FillPath(hatchBrush, path); // Add some random noise. int m = Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int) (rect.Width * rect.Height / 30F); i++) { int x = this.random.Next(rect.Width); int y = this.random.Next(rect.Height); int w = this.random.Next(m / 50); int h = this.random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } // Clean up. font.Dispose(); hatchBrush.Dispose(); g.Dispose(); // Set the image. this.image = bitmap; } }



Google

Free SMS UK Free SMS Ireland SMS Gratis Norway SMS Gratis Sverige Ilmainen SMS Suomi SMS Gratis Danmark SMS Tasuta Eestisse SMS Nemokamai Lietuva SMS Bezmaksas Latviju Darmowe smsy Polska SMS Zdarma Ceské SMS Zdarma Slovensko SMS Gratis Deutschland SMS Gratis Schweiz SMS Gratis Österreich SMS Gratuit Belgique SMS Gratis Nederland SMS Gratuit France SMS Gratis Espańa SMS Gratis Portugal Free SMS South Africa Free SMS USA SMS Percuma Malaysia Free SMS Hong Kong