First, here's the principle.
In a login screen, put an image on the interface, and then add a new item named validatecode.aspx page
Add a new page and write the following code in the newly created page:
private int codelen = 4;//captcha length private int fineness = 85;//picture sharpness private int imgwidth = 48;//picture width private int imgheight = 24;//picture Height private string fontFamily = "Times New Roman";//font name private int fontSize = 14;//font size private int fontstyle = 0 ;//font style private int posX = 0;//Draw starting coordinates x private int posY = 0;//Draw coordinates y private string Createvalidatecode ()//Generate verification code {string V Alidatecode = ""; Random random = new random (), or//stochastic object for (int i = 0; i < Codelen; i++)//loop generates each bit value {int n = random. Next (10);//digital Validatecode + = n.tostring (); } session["Vcode"] = validatecode;//Save Verification Code return validatecode;//back verification code} private void Disturbbitmap (Bitmap Bitmap)//image Background { Random random = new random ();//generate for (int i = 0; i < bitmap) by randomly number. Width; i++)//Generate {for (int j = 0; J < bitmap) per pixel by loop nesting. Height; J + +) {if (random. Next (<= this.fineness) bitmap. SetPixel (I,j,color.lightgray); }}} private void Drewvalidatecode (Bitmap bitmap,string validatecode)//Draw Verification code image {Graphics g = graphics.fromimage (Bitmap); //Gets the drawing object font font = new Font (fontfamily,fontsize,fontstyle.bold);//sets the drawing font g.drawstring (Validatecode,font, Brushes.black,posx,posy);//Draw Captcha Image}
Then write in Page_Load (object sender, EventArgs e):
Finally run the code, the following style appears:
Asp. NET Implementation Verification code