Archive
<novembre 2024>
lunmarmergiovensabdom
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678
News -
Image Hosted by ImageShack.us
By ale73 at 2012-02-15

To provide a captcha system I have created the following step


  • Create a rectangle

  • Create random number from 1 to 10000
  • Add random lines across the rectangle

  • Add random point across the rectangle



using System.Drawing and System.Drawing.Image here is the code in Page looa of Default.aspx.cs



protected void Page_Load(object sender, EventArgs e)
{

Response.ContentType = "image/png";

Random r= new Random();
int numr = r.Next(100000);
Bitmap img = new Bitmap(400, 100);
Graphics g = Graphics.FromImage(img);
g.FillRectangle(Brushes.Blue, 0, 0, 400, 200);
Font f = new Font("Arial", 30);
g.DrawString(Convert.ToString(numr), f, Brushes.White, 120, 20);
Pen p = new Pen(Color.Yellow, 2);
Random rp = new Random();
Random r2 = new Random();

int n = r2.Next(0, 5);
for (int i = 0; i <= n; i++)
{
int nrp = rp.Next(0, 100);

g.DrawLine(p, 0, nrp, 400, nrp);
}
int numpunti = r2.Next(0, 500);
System.Drawing.Image imgp = System.Drawing.Image.FromFile(Server.MapPath("puntorosso2.png"));
for (int j = 0; j < numpunti; j++)
{
int x1 = rp.Next(0, 400);
int y1 = rp.Next(0, 100);
g.DrawImage(imgp, x1, y1);
}
img.Save(Response.OutputStream, ImageFormat.Png);
g.Dispose();
img.Dispose();
imgp.Dispose();
Response.End();
}



if you want iclude in your page, you can do this by

here is the code to download

captcha.rar
Login or Register
Information of Blog
Home
Welcome all!!
Last Posts
Categories
classic ASP (2)
DotNET (3)