A
computer program or system intended to distinguish human from machine
input, typically as a way of thwarting spam and automated extraction of
data from websites.
It is generally used to check whether you are a robot or a uman being.
There are two basic alternatives on how to generate the content of the captcha
- Submit a string that should be used
- Automatically generate a random string. If this alternative is chosen then the user of the library should save the created string and compare it to what the user enters.
Add some control in web form .. take 2 button control one button control is used to generate random captcha code and second one is used to verify the code is match or not. And add one pictureBox control to show image in web form and one textBox control for verify text.
In .cs file write some code -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
LoadCaptcha();
}
int num = 0;
private void LoadCaptcha()
{
//throw new NotImplementedException();
Random r1 = new Random();
num = r1.Next(100,999);
var img = new Bitmap(this.pictureBox1.Width,this.pictureBox1.Height);
var font = new Font("Arial",30,FontStyle.Bold,GraphicsUnit.Pixel);
var graphics = Graphics.FromImage(img);
graphics.DrawString(num.ToString(),font,Brushes.Red,new Point(0,0));
pictureBox1.Image = img;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void generateBtn_Click(object sender, EventArgs e)
{
LoadCaptcha();
}
private void verifyBtn_Click(object sender, EventArgs e)
{
if (textBox1.Text==num.ToString())
{
MessageBox.Show("captcha match");
}
else
{
MessageBox.Show("captcha not match");
}
}
}
}
Comments
Post a Comment