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

     1     public class ValidateImageCode:IHttpHandler,System.Web.SessionState.IRequiresSessionState
     2     {
     3 
     4         //一般处理程序中使用Session必须实现IRequiresSessionState接口
     5         public void ProcessRequest(HttpContext context)
     6         {
     7             context.Response.ContentType = "text/html";
     8             Common.ValidateCode validatecode = new Common.ValidateCode();
     9             string validateLength=validatecode.CreateValidateCode(5);
    10             context.Session["validatecode"] = validateLength;
    11             validatecode.CreateValidateGraphic(validateLength,context);
    12         }
    13 
    14         public bool IsReusable
    15         {
    16             get
    17             {
    18                 return false;
    19             }
    20         }
    21     }
    生成验证码
    1 public void ProcessRequest(HttpContext context)
    2     {
    3             context.Response.ContentType = "text/plain";
    4             Common.ValidateCode validatecode = new Common.ValidateCode();
    5             string validateLength=validatecode.CreateValidateCode(5);
    6             validatecode.CreateValidateGraphic(validateLength,context);
    7         }
    验证码
        protected bool CheckValidateCode()
            {
                //定一个变量
                bool isSucess = false;
                //校验Session的时候一定校验是否为空,因为S有过期时间,ToString()的时候会报异常
                if(Session["validatecode"] != null)
                {
                    string txtCode = Request.Form["txtVcode"];
                    string sysCode = Session["validatecode"].ToString();
                    if(sysCode.Equals(txtCode,StringComparison.InvariantCultureIgnoreCase))
                    {
                        isSucess = true;
                        //一定要清空,安全问题。如果不清空 暴力破解 不断猜测随机生成用户名和密码
                        Session["validatecode"] = null;
                    }
                }
                return isSucess;
            }
    验证验证码
     1     <script src="../Js/jquery-1.7.1.js"></script>
     2     <script type ="text/javascript">
     3         $(function () {
     4             $("#kanbuqing").click(function () {
     5                 $("#imgVCode").attr("src","ValidateImageCode.ashx?date=" + new Date().getSeconds());
     6             });
     7         });
     8     </script>
     9 
    10         vcode:<input type="text" name="txtVcode" /><img src="ValidateImageCode.ashx" id="imgVCode" /><a href="javascript:void(0)" id="kanbuqing">看不清?</a><Br />
    展示验证码
  • 相关阅读:
    C#中抽象类和接口
    ArcGIS for Flex中引入google map作底图
    USB、UART、SPI等总线速率
    步步详解之第1节----ALTERA FPGA关于PLL的使用,帮你用光所有PLL
    FPGA笔试必会知识点2—FPGA器件
    FPGA笔试必会知识点1--数字电路基本知识
    (转)modelsim-win64-10.1c的安装
    基于FPGA的温度采集显示与报警
    基于FPGA的步进电机说明文档
    基于FPGA的直流电机
  • 原文地址:https://www.cnblogs.com/ligtcho/p/6564428.html
Copyright © 2011-2022 走看看