|
# Region implements a verification code class
Public class validatecode
{
Private bitmap validateimage;
Private graphics g;
Public validatecode ()
{
Validateimage = new Bitmap (120, 30, pixelformat. format24bpprgb );
G = graphics. fromimage (validateimage );
}
Public void drawvalidatecode (page e, string I)
{
G. drawstring (I, new font ("", 16, fontstyle. Bold), new solidbrush (color. White), new pointf (2, 4 ));
G. fillrectangle (New lineargradientbrush (new point (), new point (), color. fromargb (0, 0, 0), color. fromargb (255,255,255,255 );
// Validateimage. Save (E. outputstream, imageformat. JPEG );
G. Save ();
Memorystream MS = new memorystream ();
Validateimage. Save (MS, system. Drawing. imaging. imageformat. GIF );
E. Response. clearcontent ();
E. Response. contenttype = "image/GIF ";
E. Response. binarywrite (Ms. toarray ());
E. Response. End ();
// Validateimage. Save (E. mappath ("numimage/validateimage.gif"), imageformat. GIF );
// E. End ();
}
}
# Endregion
private void makevalidatecode ()
{< br> char [] S = new char [] {"0", "1", "2 ", "3", "4", "5", "6", "7", "8", "9", "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" };< br> string num = "";
random r = new random ();
for (INT I = 0; I <5; I ++)
{< br> num + = s [R. next (0, S. length)]. tostring ();
}< br> (loginuserinfo) session ["loginuserinfo"]). validatenum = num;
textbox3.text = "";
}
|