验证码图片生成代码
using System.Drawing;
public partial class Pub_validcode : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.CreateCheckCodeImage(GenerateCheckCode());
}
//生成随机数
private string GenerateCheckCode()
{
int number;
char code;
string checkCode = String.Empty;
System.Random random = new Random();
for (int i = 0; i < 4; i++)
{
number = random.Next();
if (number % 2 == 0)
code = (char)(0 + (char)(number % 10));
else
code = (char)(0 + (char)(number % 10));
//code = (char)(a + (char)(number % 26));
checkCode += code.ToString();
}
Response.Cookies.Add(new HttpCookie("CheckCode", checkCode));
//将生成的随机数保存到session中
Session["Num"] = checkCode.ToString().ToLower();
return checkCode;
}
private void CreateCheckCodeImage(string checkCode)
{
if (checkCode == null || checkCode.Trim() == String.Empty)
retu
补充:软件开发 , C# ,