Search

Monday, March 9, 2015
0 comments

Code of Image Captcha in windows form c#

1:26 AMMonday, March 9, 2015
Image captcha is used for human verification. Actually some bots machine is used for creating back links to the blog/website. If you want to stop that machine, create human verification captcha. There are two types, first one is string based and another one is numbered based captcha. In this example, i will implement number based captcha.
Learn, how to design numbered based captcha. Actually, we will write some randomly generated number on image. After that we compare that number with the text box.

Video Contain Full code implementation details:

Copy this code and paste in the code file:

  int number = 0;
        private void createcaptcha()
        {
            Random r1 = new Random();
            number = r1.Next(10, 1000);
            Image img = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
            var font = new Font("TimesNewRoman", 25, FontStyle.Bold, GraphicsUnit.Pixel);
            var graphics = Graphics.FromImage(img);
            graphics.DrawString(number.ToString(), font, Brushes.Red, new Point(0, 0));
            this.pictureBox1.Image = img;
     
        }

   private void refresh_Click(object sender, EventArgs e)
        {
            createcaptcha();

        }

private void verify_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == number.ToString())
            {
                MessageBox.Show("match");
            }
            else
            {
                MessageBox.Show("not match");
            }
        }

Here,

  1. Bitmap class is used for picking width and height parameter from the picture box.
  2. Using Font class, set the font style, font family and graphics unit that is pixel.
  3. Using Graphics class draw string on the picture, i have used randomly generated number.
  4. Now, assign the image to the picture box.

Code Generate the following output

Code of Image Captcha in windows form c#
Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top