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

    手写验证码

    Html:

                                        <div class="field">
                                            <input type="text" class="input input-big" name="code" placeholder="填写右侧的验证码" data-validate="required:请填写右侧的验证码" />
                                            <img src="/Login/ShowVCode" id="LoginCode" alt="" width="100" height="32" class="passcode" style="height:43px;cursor:pointer;" onclick="this.src=this.src+'?'">
                                        </div>
                                       
                                    </div>

    控制器:

       #region 验证码生成
            public ActionResult ShowVCode()
            {
                ValidateCode validateCode = new ValidateCode();
                string strCode = validateCode.CreateValidateCode(4);
                Session["VCode"] = strCode;
                byte[] imgBytes = validateCode.CreateValidateGraphic(strCode);
                return File(imgBytes, @"image/jpeg");
            }
            #endregion

    在控制器上怎么接受到验证码:

    #region 验证
            public ActionResult Logincode()
            {
            
                string strCode = Request["code"];//接收到的Code
                string sessionCode = Session["VCode"] as string;//生成的Code
                Session["VCode"] = null;
                if (string.IsNullOrEmpty(sessionCode))
                {
                    //return Content("验证码失败");
                    return Redirect("Index");
                }
                if (strCode == sessionCode)
                {
                    // return Content("验证码正确");          
                   // return Redirect("/Shopper/Index");
                    return RedirectToAction("Index", "Shopper", new { name = UserName }); 
                }
                else
                {
                    //return Content("验证码失败");
                    return Redirect("Index");
                }
            }
            #endregion
  • 相关阅读:
    5.集合(3)——Map集合
    4.集合(3)——List集合
    2.初窥集合类1
    1.正则表达式1
    (13)JSON
    (12)表单验证
    Wpf实现TreeSelect多选
    Wpf实现TreeSelect
    Wpf登录验证方式(5)-推理拼图的实现
    Wpf登录验证方式(4)-语序点选的实现
  • 原文地址:https://www.cnblogs.com/mvpbest/p/13443237.html
Copyright © 2011-2022 走看看