标签:
/// <summary> /// 创建验证码 /// </summary> /// <param name="contro"></param> public static void GetVerify(Controller contro) { string key = "ADMIN_VERIFY_" + contro.Session["AdminSession"]; int x = ran.Next(1, 10), y = ran.Next(1, 10), result = 0; //获取算式和答案 StringBuilder sb = new StringBuilder(); sb.Append(x); switch (ran.Next(1, 3)) { case 1: sb.Append(" + "); result = x + y; break; default: sb.Append(" × "); result = x * y; break; } sb.Append(y).Append(" = ? "); //将算式输出为图片 using (Bitmap b = new Bitmap(100, 28)) using (Graphics g = Graphics.FromImage(b)) using (Font font = new Font("Microsoft YaHei", 15)) { g.DrawString(sb.ToString(), font, Brushes.White, 0, 0); b.Save(contro.Response.OutputStream, ImageFormat.Jpeg); } //将答案写入redis,2分钟 WebHelper.WriteRedisKey(key, result.ToString(), DateTime.Now.AddMinutes(2));
标签:
原文地址:http://www.cnblogs.com/Darkon/p/5412119.html