1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| using System;
using System.IO;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Drawing.Drawing2D;
public class CaptchaHandler : IHttpHandler
{
void captcha (string CheminSauvegarde)
{
///============================================
///GENERATION ALEATOIRE DU CODE A 6 CARACTERES
///============================================
Random Ran = new Random();
string Str = "";
string[] Alpha = {"a","b","c","d","e","f","g","h","i","j",
"k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
"Q","R","S","T","U","V","W","X","Y","Z","0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
for (int i = 0; i <= 5; i++)
{
int intRanAlpha = Ran.Next(0, 61);
Str = Str + Alpha[intRanAlpha].ToString();
}
Alpha = null;
Ran = null;
///============================================
///CREATION IMAGE ET SAUVEGARDE
///============================================
Bitmap Img = new Bitmap(85, 35, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics Gr = Graphics.FromImage(Img);
SizeF sizeff = Gr.MeasureString(Str, new Font("Arial", 25, FontStyle.Strikeout, GraphicsUnit.Pixel), 300);
HatchBrush hatchBrush = new HatchBrush(HatchStyle.Wave, Color.DarkBlue, Color.Gray);
Gr.FillRectangle(hatchBrush, new Rectangle(0, 0, 85, 35));
Gr.DrawString(Str, new Font("Arial", 15, FontStyle.Strikeout, GraphicsUnit.Point), Brushes.White, 5, 5);
Img.Save(CheminSauvegarde);
}
public bool IsReusable
{
get
{
return true;
}
}
public void ProcessRequest(System.Web.HttpContext context)
{
captcha("F:\\users\\web-inscriptions.fr\\httpdocs\\Captcha\\Capcha.jpg");
System.Drawing.Image Img = System.Drawing.Image.FromFile("F:\\users\\web-inscriptions.fr\\httpdocs\\Captcha\\Capcha.jpg");
Img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Img.Dispose();
}
} |
Partager