Introduction
A CAPTCHA (acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart") is a type of challenge-response test used in computing to determine whether or not the user is human.
We are all aware of the requirement of a “CAPTCHA Library” or plugin to generate a CAPTCHA image or text based image. But it may require more time to develop your product for a developer. Since we are always hungry to grab everything in time and in hand it in in the softest way. We all belong to the Ninja Generation (Fastest).
We can simply download or generate a few images having some text or numbers. A good number of image editors currently are freely available in the market now-a-days. So I can expect it to be easy. After obtaining these images put all of them in the Images folder of your Visual Developer Solution file.
Now for the actual implementation. Select the “ASP” file or WebForm where you want to invoke your CAPTCHA. I created there an image button followed by a TextBox (where the user will enter data written in a CAPTCHA image). Then go to the aspx.cs file and provide the following code segment within Page Load.
- static int a = 0;
-
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- DateTime now = DateTime.Now;
- int s = now.Second;
- a = s % 10;
- if (a == 0)
- {
- ImageButton1.ImageUrl = "~/imge/0.jpg";
- }
- if(a == 1)
- {
- ImageButton1.ImageUrl = "~/imge/1.jpg";
- }
- ……………………………………………………………..
- …………………………………………………….
- }
- }
-
-
-
- protected void Button1_Click(object sender, EventArgs e)
- {
- switch (a)
- {
- case 0:
- if (TextBox1.Text == "abc")
- {
- Response.Write("You are a man…");
- }
- else
- {
- Response.Write("Robot Found.. Try Again");
- Response.Redirect(Request.RawUrl.ToString());
- }
- break;
- case 1:
- if (TextBox1.Text == "def")
- {
- Response.Write("You are a man..");
- }
- else
- {
- Response.Write("Robot found .. try again");
- Response.Redirect(Request.RawUrl.ToString());
- }
- break;
- ………………………………………………….
- ……………………………………………………………………………………………………
-
- }
- }