The original Published time: 2008-09-22--from my Baidu article [imported by moving tools]
Reference: http://www.cnblogs.com/gwazy/articles/139510.html
Three forms:
DEFAULT1:
Property value:
Source:
<%@ page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Untitled Page </title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:textbox id= "TextBox1" runat= "Server" ></asp:TextBox>
<asp:imagebutton id= "ImageButton1" runat= "Server" causesvalidation= "False" height= "35px"
Imageurl= "~/default2.aspx" tooltip= "can't see the picture?" Click Replace "width=" 75px "/><br/>
<br/>
<asp:button id= "Button1" runat= "Server" text= "button" onclick= "Button1_Click"/></div>
</form>
</body>
Code:
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
}
protected void Button1_Click (object sender, EventArgs e)
{
if (String.Compare (TextBox1.Text, session["Checkcode"]. ToString (), true) ==0)
{
Response.Redirect ("~/default3.aspx");
}
}
}
Default2 is empty form:
Code:
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.Design;
Using System.IO;
public partial class Default2:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
System.Random rd = new Random ();
int number;
char code;
String checkcode=string. Empty;
for (int i = 0; i < 4; i++)
{
Number = Rd. Next ();
if (number% 2 = = 0)
Code = (char) (' 0 ' + (char) (number% 10));
Else
Code = (char) (' A ' + (char) (number% 26));
Checkcode + = code. ToString ();
}
session["Checkcode"] = Checkcode;
Bitmap bp = new Bitmap (75, 35);
Graphics g = Graphics.fromimage (BP);
G.clear (Color.White);
for (int i = 0; i <; i++)
{
int x1 = Rd. Next (BP. Width);
int y1 = Rd. Next (BP. Height);
int x2 = Rd. Next (BP. Width);
int y2 = Rd. Next (BP. Height);
G.drawline (New Pen (Color.aqua), x1, y1, x2, y2);
}
Font ft = new Font ("Arial", FontStyle.Bold | Fontstyle.italic);
System.Drawing.Drawing2D.LinearGradientBrush LGB = new System.Drawing.Drawing2D.LinearGradientBrush (new Rectangle (0 , 0, BP. Width, BP. Height), Color.Blue, color.blue,10, true);
g.DrawString (Checkcode, FT, LGB, 2, 2);
for (int i = 0; i <; i++)
{
int x = Rd. Next (BP. Width);
int y = Rd. Next (BP. Height);
Bp. SetPixel (x, Y, Color.FromArgb (Rd. Next ()));
}
G.drawrectangle (New Pen (Color.silver), 0, 0, BP. Width-1, BP. HEIGHT-1);
MemoryStream ms = new MemoryStream ();
Bp. Save (MS, SYSTEM.DRAWING.IMAGING.IMAGEFORMAT.GIF);
Response.clearcontent ();
Response.ContentType = "Image/gif";
Response.BinaryWrite (Ms. ToArray ());
G.dispose ();
Ms. Dispose ();
Ms. Close ();
}
}
Default3 is empty form (use of MD5 value):
Code:
public partial class Default3:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
String md5= System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (session["Checkcode"]. ToString (), "MD5");
Response.Write (MD5);
}
}
C#.net Make verification code (4-bit random number consisting of English and numerals), and use of MD5 value