有验证码的登陆界面(ajax,ashx技术制作)(2)
Random rand = new Random();
for (int i = 0; i < n; i++)
{
if (temp != -1)
{
rand = new Random(i * temp * ((int)DateTime.Now.Ticks));
}
int t = rand.Next(CharArray.Length - 1);
if (temp == t)
{
return CreateRandomCode(n);
}
temp = t;
randomCode += CharArray[t];
}
return randomCode;
}
private void CreateImage(string checkCode, HttpContext context)
{
int iwidth = (int)(checkCode.Length * 13);
System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth, 23);
Graphics g = Graphics.FromImage(image);
Font f = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Italic | System.Drawing.FontStyle.Bold));
// 前景色
Brush b = new System.Drawing.SolidBrush(Color.Black);
// 背景色
g.Clear(Color.White);
// 填充文字
g.DrawString(checkCode, f, b, 0, 1);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>