Captcha for your application

The term "CAPTCHA" (based upon the word capture) was coined in 2000 by Luis Von Ahn, Manuel Blum, Nicholas J. Hopper, and John Langford (all of Carnegie Mellon University).

It is a acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart."

A CAPTCHA or Captcha is a type of Challenge-Responce test used in computing to ensure that the response is not generated by a computer. The process usually involves one computer (server) asking a user to complete a simple test which the computer is able to generate and grade. Because other computers are unable to solve the CAPTCHA, any user entering a correct solution is presumed to be human.

CAPTCHAs are used to prevent automated software from performing actions which degrade the quality of service of a given system, whether due to abuse or resource expenditure.


Simple Captcha :



Example Code :

In BuildCaptcha.aspx.cs :

using System.Web.UI.HtmlControls;

using System.Drawing;

using System.Text;

using System.Drawing.Text;

using System.Drawing.Imaging;

public partial class BuildCaptcha: System.Web.UI.Page


protected void Page_Load(object sender, EventArgs e)


Bitmap objBMP = new Bitmap(60, 20);

Graphics objGraphics = Graphics.FromImage(objBMP);


objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;

Font objFont = new Font("Arial", 8, FontStyle.Italic);

string randomStr = "";

char[] myArray = new char[5];

int x;

Random autoRand = new Random();

for (x = 0; x < 5; x++)


myArray[x] = System.Convert.ToChar(autoRand.Next(65,90));

randomStr += (myArray[x].ToString());


Session.Add("RandomStr", randomStr);

objGraphics.DrawString(randomStr, objFont, Brushes.Red, 3, 3);

Response.ContentType = "image/GIF";

objBMP.Save(Response.OutputStream, ImageFormat.Gif);






In Verification.aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Verification.aspx.cs" Inherits="Captch" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""&gt;

<html xmlns="; >

<head runat="server">

<title>Verification Page</title>



<form id="form1" runat="server">


<img height="30" alt="" src="BuildCaptcha.aspx" width="80" />

<br />

<asp:TextBox runat="Server" ID="txtCaptcha"/>

<asp:Button runat="Server" ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" />





In Verification.aspx.cs :

public partial class Verification : System.Web.UI.Page


protected void btnSubmit_Click(object sender, EventArgs e)


if (Page.IsValid && (txtCaptcha.Text.ToString() == Session["RandomStr"].ToString()))


Response.Write("Code verification Successful");

// Proceed for next action




Response.Write( "Please Enter Information correctly");





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s