FindPwd/RandonNum.aspx.cs
(完整代码) 2KBusing 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;
public partial class RandonNum : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str = Getrandom();
//存储验证码
Session["code"] = str;
//图(取绝对路径)
System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("Image/1.jpg"));
//绘图对象(指向图)
Graphics g = Graphics.FromImage(img);
//在图上写字
//g.DrawString(str, new Font("Airal", 1, FontStyle.Bold), Brushes.Red, new Point(0, 0));
//Font font = new System.Drawing.Font("Arial", 25, FontStyle.Bold);
Font font = new System.Drawing.Font("", 25, FontStyle.Bold);
//渐变色彩
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Tomato, Color.Red, 1.8f, true);
//g.DrawString(str,font, brush, 2, 2);
g.DrawString(str, font, brush, 8, -1);
//画图片的边框线
g.DrawRectangle(new Pen(Color.Silver), 0, 0, img.Width - 1, img.Height - 1);
// 下载于www.51aspx.com
//保存图片
img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
private string Getrandom()
{
//获取随机数
Random rand = new Random();
//获取四位的随机数
int i = rand.Next(1000, 10000);
//获取由数字和字母组成的随机数
string[] str = new string[] { "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" };
string code = string.Empty; //只读
for (int j = 0; j < 4; j++)
{
i = rand.Next(0, 36);
code += str[i];
}
return code;
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。