Hi,
We know the captcha control, but now a day so many captcha code is available, most of the captcha is only for the text, but here I explain the new captcha that want human in intelligence as like arithmetic expression.
Create the new project,
Add a new file for create the captcha control named “captcha.aspx”.
In the page load of the captcha.aspx page.
protected void Page_Load(object sender, EventArgs e)
{
returnNumer();
}
void returnNumer()
{
Random num1 = new Random();
Random num2 = new Random();
int numQ1, numQ2;
string QString;
numQ1 = num1.Next(10, 15);
numQ2 = num1.Next(17, 31);
QString = numQ1.ToString() + " + " + numQ2.ToString() + " = ";
Session["answer"] = numQ1 + numQ2;
Bitmap bitmap = new Bitmap(85,25);
Graphics Grfx = Graphics.FromImage(bitmap);
Font font = new Font("Arial", 18, FontStyle.Bold, GraphicsUnit.Pixel);
Rectangle Rect = new Rectangle(100, 0, 0, 0);
Grfx.FillRectangle(Brushes.Brown, Rect);
Grfx.DrawRectangle(Pens.PeachPuff, Rect);
// Border
Grfx.DrawString(QString, font, Brushes.Azure, 0, 0);
Response.ContentType = "Image/jpeg";
bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
bitmap.Dispose();
Grfx.Dispose();
}
Now in the default.aspx page take some control and 1 image control for the display captcha.
<body> <form id="form1" runat="server"> <div> Are You Human? <asp:image ID="Image1" runat="server" ImageUrl="Capcha.aspx" /> <asp:TextBox ID="txtInput" runat="server"></asp:TextBox> <br /><br /> <asp:Button ID="Btnsubmit" runat="server" Text="Submit" onclick="Btnsubmit_Click" /><br /><br /> <asp:Label ID="lblValidate" runat="server"></asp:Label> </div> </form> </body>
To check the input is valid or not, check the session value for the arithmetic expression.
So in default.aspx.cs file
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Btnsubmit_Click(object sender, EventArgs e)
{
if (Session["answer"] != null)
{
if (Session["answer"].ToString() == txtInput.Text)
{
lblValidate.Text = "Current Answer";
}
else
{
lblValidate.Text = "Incurrent Answer, Please input Valid Answer.";
}
}
}
Now run the page

inter the result and click the button
if result is currect then
and if answer id not currect then,

Hope this will help you…
Thanks.






