zoukankan      html  css  js  c++  java
  • 验证码

    20160204 简单加减乘除验证码

    UI

    前台UI:
            <div class="row bg-info">
             <form action="Login.ashx" method="post">
                <div>
                  <img style="80px;height:30px;" src="getpic.ashx"/>
                        </div>
                <div>
                    <input type="text" name="pic" /><input type="submit" value="提交" />
                </div>
                  </form>
             </div>
    后台代码验证:
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/html";
    
                if (context.Request["pic"] != null)
                {
                    if (context.Request["pic"] == context.Session["pic"].ToString())
                        context.Response.Write("ok");
                    else
                        context.Response.Write("no");
                }
    
            }
    View Code

    类库:

            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "image/jpeg";
                //1. creat bitmap
                using (Image image = new Bitmap(80, 30))
                {
                    //2. creat string
                    Graphics g = Graphics.FromImage(image);
                    //3. start draw string
                    g.DrawString(GetString(), new Font("幼圆", 10), Brushes.Yellow, new Point(10, 10));
                    //4. list pic
                    image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                }
            }
            private string GetString()
            {
                Random rd = new Random();
                int N1 = rd.Next(10);
                int N2 = rd.Next(10);
                int com = rd.Next(3);// 运算符,operator
                int sum = 0 ;
                string str = "";
    
                switch (com) {
                    case 0:sum = N1 + N2; str = N1 + " + " + N2 + " = "; break;
                    case 1:sum = N1 - N2; str = N1 + " - " + N2 + " = "; break;
                    case 2:sum = N1 * N2; str = N1 + " × " + N2 + " = "; break;
                    default:str = "error";break;
                }
               HttpContext.Current.Session.Add("pic", sum);//生成一个名为session的值
                return str;
            }
    View Code
  • 相关阅读:
    android 的 ExpandableListView Example Tutorial
    EOS token 代币兑换的资料
    EOS 的网站及资料doc
    Cardano(ADA), EOS, RChain(RHOC), Aeternity(AE) 都是极其好的币
    zcash 的资料
    office很抱歉遇到一些临时服务器问题
    win10windows无法创建快捷方式 请检查磁盘
    FYI是什么意思?
    Wamp win10 1077error
    如何注销考拉?
  • 原文地址:https://www.cnblogs.com/0to9/p/5181434.html
Copyright © 2011-2022 走看看