how to use captcha image in asp.net

Posted by Shanky11 under ASP.NET on 8/18/2014 | Points: 10 | Views : 413 | Status : [Member] | Replies : 1
how to check this image in code behind on registeration button click


<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;

public class Handler : IHttpHandler {

public void ProcessRequest (HttpContext context) {
using (Bitmap b = new Bitmap(150, 40, PixelFormat.Format32bppArgb))
{
using (Graphics g = Graphics.FromImage(b))
{
Rectangle rect = new Rectangle(0, 0, 149, 39);
g.FillRectangle(Brushes.White, rect);

// Create string to draw.
Random r = new Random();
int startIndex = r.Next(1, 5);
int length = r.Next(5, 10);
String drawString = Guid.NewGuid().ToString().Replace("-", "0").Substring(startIndex, length);

// Create font and brush.
Font drawFont = new Font("Arial", 16, FontStyle.Italic | FontStyle.Strikeout);
using (SolidBrush drawBrush = new SolidBrush(Color.Black))
{
// Create point for upper-left corner of drawing.
PointF drawPoint = new PointF(15, 10);

// Draw string to screen.
g.DrawRectangle(new Pen(Color.Red, 0), rect);
g.DrawString(drawString, drawFont, drawBrush, drawPoint);
}
b.Save(context.Response.OutputStream, ImageFormat.Jpeg);
context.Response.ContentType = "image/jpeg";
context.Response.End();
}
}
}

public bool IsReusable {
get {
return false;
}
}

}




Responses

Posted by: Kmandapalli on: 8/18/2014 [Member] Silver | Points: 25

Up
0
Down
Hi,

Please go through the link below,

http://www.codeproject.com/Articles/169371/Captcha-Image-using-C-in-ASP-NET

Mark as answer if satisfied.....

Regards,
Kavya M.

Kavya Shree Mandapalli

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response