|
Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. drawing;
Using system. Drawing. imaging;
Using system. IO;
Public partial class identifyingcode: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
String TMP = rndnum (4 );
Httpcookie A = new httpcookie ("imagev", TMP );
Response. Cookies. Add ();
This. validatecode (TMP );
}
Private void validatecode (string vnum)
{
Bitmap IMG = NULL;
Graphics G = NULL;
Memorystream MS = NULL;
Int gheight = vnum. length * 12;
IMG = new Bitmap (gheight, 25 );
G = graphics. fromimage (IMG );
// Background color
G. Clear (color. lightsteelblue );
// Text font
Font F = new font ("Arial black", 10 );
// Text color
Solidbrush S = new solidbrush (color. royalblue );
G. drawstring (vnum, F, S, 3, 3 );
MS = new memorystream ();
IMG. Save (MS, imageformat. JPEG );
Response. clearcontent ();
Response. contenttype = "images/JPEG ";
Response. binarywrite (Ms. toarray ());
G. Dispose ();
IMG. Dispose ();
Response. End ();
}
Private string rndnum (INT vcodenum)
{
String vchar = ", 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 ";
String [] vcarray = vchar. Split (New char [] {','});
String vnum = "";
Int temp =-1;
Random Rand = new random ();
for (INT I = 1; I {< br> If (temp! =-1)
{< br> Rand = new random (I * temp * unchecked (INT) datetime. now. ticks);
}
Int T = Rand. Next (35 );
If (temp! =-1 & temp = T)
{
Return rndnum (vcodenum );
}
Temp = T;
Vnum + = vcarray [T];
}
Return vnum;
}
}
|