Пример #1
0
        /// <summary>
        /// 登录验证码
        /// </summary>
        public void VerifyCode_GET()
        {
            string     word = null;
            VerifyCode v    = new VerifyCode();
            var        font = v.GetDefaultFont();

            try
            {
                font          = new System.Drawing.Font(font.FontFamily, 16);
                v.AllowRepeat = false;
                Response.BinaryWrite(v.GraphicDrawImage(4,
                                                        VerifyWordOptions.Letter,
                                                        !true,
                                                        font,
                                                        60,
                                                        out word));
                VerifyCodeManager.AddWord(word);
                Response.ContentType = "Image/Jpeg";
            }
            catch (Exception exc)
            {
                if (font != null)
                {
                    font.Dispose();
                }
                throw exc;
            }
        }
Пример #2
0
 public ActionResult GetPicCaptchas()
 {
     var codeMaker = new VerifyCode();
     codeMaker.SetPageNoCache(Response);
     Session["picVerify"] = codeMaker.Paint(Response.OutputStream);
     return null;
 }
        /// <summary>
        /// 验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult GetAuthCode()
        {
            VerifyCode verifyCode = new VerifyCode();

            byte[] img = verifyCode.GetVerifyCode();
            return(File(img, @"image/png"));
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //禁用客户端缓存
            Response.Buffer          = true;
            Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
            Response.Expires         = 0;
            Response.CacheControl    = "no-cache";

            VerifyCode v = new VerifyCode();

            v.Length = this.length;

            v.FontSize = this.fontSize;

            v.Chaos = this.chaos;

            v.BackgroundColor = this.backgroundColor;

            v.ChaosColor = this.chaosColor;

            v.CodeSerial = this.codeSerial;

            v.Colors = this.colors;

            v.Fonts = this.fonts;

            v.Padding = this.padding;

            string code = v.CreateVerifyCode();             //取随机码

            v.CreateImageOnPage(code, this.Context);        // 输出图片

            Session["CheckVerifyCode"] = code.ToLower();    // 使用Session["CheckCode"]取验证码的值
            //Response.Cookies.Add(new HttpCookie("VerifyCode", code.ToLower()));// 使用Cookies取验证码的值
        }
Пример #5
0
        public string Post(FormCollection form)
        {
            const string tipFMT = "<script type=\"text/javascript\">alert('{0}')</script>";

            string nickname   = form["post_name"],
                   title      = form["post_title"],
                   tag        = form["post_type"],
                   verifyCode = form["verifycode"],
                   content    = form["editor"];

            if (content.Length == 0)
            {
                return(String.Format(tipFMT, "请输入内容"));
            }
            else if (verifyCode == "" || !VerifyCode.Verify(verifyCode, true))
            {
                return(String.Format(tipFMT, "验证码不正确!"));
            }
            Category catalog = cbll.Get(a => a.Tag == tag);

            string id = bll.Create(new Archive
            {
                Author    = nickname,
                CatalogID = catalog.ID,
                Content   = content,
                Tags      = "",
                Source    = "",
                Title     = title,
                ViewCount = 1,
                Visible   = true
            });

            return(String.Format("<script type=\"text/javascript\">alert('发布成功!');window.parent.location.href='/s_{0}/';</script>", id));
        }
Пример #6
0
        public IActionResult GetVerifyCodeImage()
        {
            string code = string.Empty;

            byte[] buffer = VerifyCode.Create(4, out code);
            return(File(buffer, @"image/jpeg"));
        }
Пример #7
0
        /// <summary>
        /// 验证码
        /// </summary>
        public void VerifyImage()
        {
            VerifyCode v = new VerifyCode();

            v.AllowRepeat = false;
            v.DisplayAsVerifyImage(4, VerifyWordOptions.Letter);
        }
Пример #8
0
        public string Show(string id, FormCollection form)
        {
            const string tipFMT = "<script type=\"text/javascript\">alert('{0}')</script>";

            string view_name = form["view_name"];

            if (String.IsNullOrEmpty(view_name))
            {
                return(String.Format(tipFMT, "名称不能为空!"));
            }
            else if (form["verifycode"] == "" || !VerifyCode.Verify(form["verifycode"], true))
            {
                return(String.Format(tipFMT, "验证码不正确!"));
            }

            string content = form["editor"];

            if (content.Length == 0)
            {
                return(String.Format(tipFMT, "请输入内容!"));
            }

            //去掉HTML

            //补充用户
            content = String.Format("(u:'{0}'){1}", view_name, content);

            cmbll.InsertComment(id, 0, content);


            return("<script type=\"text/javascript\">alert('评论成功!');window.parent.location.reload();</script>");
        }
Пример #9
0
        public async Task <bool> RegisterVerifyEmail(string email)
        {
            var DB          = Context.Request.HttpContext.RequestServices.GetRequiredService <PomeloContext>();
            var EmailSender = Context.Request.HttpContext.RequestServices.GetRequiredService <IEmailSender>();

            // 将先前的验证码作废
            var codes = DB.VerifyCodes
                        .Where(x => x.Email == email && x.Type == VerifyCodeType.Register && x.Expire > DateTime.Now && !x.IsUsed)
                        .ToList();

            foreach (var c in codes)
            {
                c.Expire = DateTime.Now;
            }

            // 将验证码信息写入数据库
            var VerifyCode = new VerifyCode {
                Expire = DateTime.Now.AddHours(1), Email = email, Code = (new Random()).Next(1000, 9999), Type = VerifyCodeType.Register
            };

            DB.VerifyCodes.Add(VerifyCode);

            DB.SaveChanges();

            await EmailSender.SendEmailAsync(email, "Retrieve Password Letter", "Your code is: " + VerifyCode.Code);

            return(true);
        }
Пример #10
0
        public async Task <ActionResult> VerifyCode(VerifyCode model)
        {
            if (!ModelState.IsValid)
            {
                //return View(model);
            }

            // The following code protects for brute force attacks against the two factor codes.
            // If a user enters incorrect codes for a specified amount of time then the user account
            // will be locked out for a specified amount of time.
            // You can configure the account lockout settings in IdentityConfig
            var result = await SignInManager.TwoFactorSignInAsync(model.Provider, model.Code, isPersistent : model.RememberMe, rememberBrowser : model.RememberBrowser);

            switch (result)
            {
            case SignInStatus.Success:
            //return RedirectToLocal(model.ReturnUrl);
            case SignInStatus.LockedOut:
            //return View("Lockout");
            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", @"Invalid code.");
                //return View(model);
            }
        }
Пример #11
0
        public IActionResult VerifyCode()
        {
            #region 防止网页后退--禁止缓存
            Response.Headers.Add("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
            Response.Headers.Add("Pragma", "no-cache");                                   // HTTP 1.0.
            Response.Headers.Add("Expires", "-1");                                        // Proxies.
            #endregion

            Random r    = new Random();
            string code = r.Next(10000, 100000).ToString();
            SetSession(SessionSetting.AdminLoginCode, code);
            VerifyCode vimg = new VerifyCode();
            vimg.FontSize = 30;
            var bytes           = vimg.CreateImageBytes(code);
            var AcceptEncodings = Request.Headers["Accept-Encoding"].ToString().Replace(" ", "").Split(',');
            if (AcceptEncodings.Contains("br"))
            {
                Response.Headers["Content-Encoding"] = "br";
                bytes = CompressionUtil.BrCompress(bytes, true);
            }
            else if (AcceptEncodings.Contains("gzip"))
            {
                Response.Headers["Content-Encoding"] = "gzip";
                bytes = CompressionUtil.GzipCompress(bytes, true);
            }
            return(File(bytes, "image/jpg"));
        }
Пример #12
0
        public async Task <IActionResult> VerifyCode(VerifyCode model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            var result = await _signInManager.TwoFactorSignInAsync(
                provider : model.Provider,
                code : model.Code,
                isPersistent : model.RememberMe,
                rememberClient : model.BrowserRemember
                );


            if (result.Succeeded)
            {
                return(RedirectToLocal(model.ReturnTo));
            }

            if (result.IsLockedOut)
            {
                return(View("LockOut"));
            }

            ModelState.AddModelError(nameof(model.Code), "کد وارد شده معتبر نمی باشد");

            return(View(model));
        }
Пример #13
0
        protected override void ParseBody()
        {
            Decrypt(_secretKey);
            VerifyType = reader.ReadByte();
            reader.BEReadChar();
            Status = reader.ReadByte();
            reader.ReadBytes(4);
            user.QQ_PACKET_00BAVerifyToken = reader.ReadBytes(reader.BEReadChar());
            VerifyCode    = reader.ReadBytes(reader.BEReadChar());
            VerifyCommand = reader.ReadByte();
            if (VerifyCommand == 0x00)
            {
                VerifyCommand = reader.ReadByte();
            }

            reader.ReadByte();
            if (user.QQ_PACKET_00BAVerifyCode?.Length == 0 || user.QQ_PACKET_00BAVerifyCode == null)
            {
                user.QQ_PACKET_00BAVerifyCode = VerifyCode;
            }
            else
            {
                var resultArr = new byte[user.QQ_PACKET_00BAVerifyCode.Length + VerifyCode.Length];
                user.QQ_PACKET_00BAVerifyCode.CopyTo(resultArr, 0);
                VerifyCode.CopyTo(resultArr, user.QQ_PACKET_00BAVerifyCode.Length);
                user.QQ_PACKET_00BAVerifyCode = resultArr;
            }

            user.QQ_PACKET_00BAToken = reader.ReadBytes(reader.BEReadChar());
            reader.ReadBytes(reader.BEReadChar());
        }
Пример #14
0
 public IActionResult GetAuthCode()
 {
     byte[] img = new VerifyCode().GetVerifyCode(out CodeString);
     //设置验证码Session
     HttpContext.Session.SetString("Code", CodeString);
     return(File(img, @"image/Gif"));
 }
Пример #15
0
        public ActionResult CreateVerifyCode()
        {
            VerifyCode vc = new VerifyCode();

            byte[] result = vc.GetVerifyCode();
            return(File(result, "image/jpeg jpeg jpg jpe"));
        }
Пример #16
0
        public ActionResult VerifyCode()
        {
            VerifyCode verify = new VerifyCode();

            WebHelper.SetSession(Keys.SESSION_KEY_VCODE, verify.Text.ToLower());
            return(File(verify.Image, "image/jpeg"));
        }
        /// <summary>
        /// 验证码
        /// </summary>
        /// <param name="context"></param>
        public void VerifyCode(HttpContext context)
        {
            string     word = null;
            VerifyCode v    = new VerifyCode();
            var        font = v.GetDefaultFont();

            try
            {
                font          = new System.Drawing.Font(font.FontFamily, 16);
                v.AllowRepeat = false;
                context.Response.BinaryWrite(v.GraphicDrawImage(4,
                                                                VerifyWordOptions.Number,
                                                                !true,
                                                                font,
                                                                30,
                                                                out word));
            }
            catch
            {
                if (font != null)
                {
                    font.Dispose();
                }
            }
            context.Response.ContentType = "Image/Jpeg";
            VerifyCodeManager.AddWord(word);
        }
Пример #18
0
        public void GenerateToDb()
        {
            List <char> Resource = new List <char> {
                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'X', 'Y', 'Z', 'T', 'U', 'V'
            };
            Random rand = new Random();

            context.Database.ExecuteSqlCommand("TRUNCATE TABLE [VerifyCodes]"); context.SaveChanges();
            for (int j = 0; j < 100; j++)
            {
                VerifyCode Randomstring = new VerifyCode();
                Randomstring.Code = "";
                for (int i = 0; i < 6; i++)
                {
                    int randnumber = rand.Next(0, Resource.Count() - 1);
                    Randomstring.Code = Resource[randnumber] + Randomstring.Code;
                }

                if (context.VerifyCodes.Find(Randomstring.Code) == null)
                {
                    context.VerifyCodes.Add(Randomstring); context.SaveChanges();
                }
                else
                {
                    j--;
                }
            }
        }
Пример #19
0
        public void VerifyImg(string length, string opt, string usefor)
        {
            int _length;                  //验证码长度
            VerifyWordOptions _opt;       //验证码选项
            string            verifycode; //验证码

            if (String.IsNullOrEmpty(length) || !Regex.IsMatch(length, "^\\d+$"))
            {
                _length = 4;
            }
            else
            {
                _length = int.Parse(length);
            }

            if (String.IsNullOrEmpty(opt) || !Regex.IsMatch(opt, "^\\d$"))
            {
                _opt = VerifyWordOptions.Number;
            }
            else
            {
                _opt = (VerifyWordOptions)int.Parse(opt);
            }

            VerifyCode v = new VerifyCode();

            v.AllowRepeat = false;

            //显示验证码
            v.RenderGraphicImage(_length, _opt, true, out verifycode, "Image/Jpeg");

            //保存验证码
            Session["$cms.verifycode"] = verifycode;
        }
Пример #20
0
        public void GetVerifyCode()
        {
            string randomcode = VerifyCode.CreateRandomCode(4);

            HttpContext.Current.Session["VerifyCode"] = randomcode;
            VerifyCode.CreateImage(randomcode);
        }
Пример #21
0
        protected override void ParseBody(ByteBuffer byteBuffer)
        {
            //密文
            byte[] CipherText = byteBuffer.ToByteArray();
            //明文
            bodyDecrypted = QQTea.Decrypt(CipherText, byteBuffer.Position, CipherText.Length - byteBuffer.Position - 1, _secretKey);
            //提取数据
            ByteBuffer buf = new ByteBuffer(bodyDecrypted);

            VerifyType = buf.Get();
            buf.GetChar();
            Status = buf.Get();
            buf.GetByteArray(4);
            user.QQ_PACKET_00BAVerifyToken = buf.GetByteArray(buf.GetChar());
            VerifyCode    = buf.GetByteArray(buf.GetChar());
            VerifyCommand = buf.Get();
            if (VerifyCommand == 0x00)
            {
                VerifyCommand = buf.Get();
            }
            buf.Get();
            if (user.QQ_PACKET_00BAVerifyCode?.Length == 0 || user.QQ_PACKET_00BAVerifyCode == null)
            {
                user.QQ_PACKET_00BAVerifyCode = VerifyCode;
            }
            else
            {
                byte[] resultArr = new byte[user.QQ_PACKET_00BAVerifyCode.Length + VerifyCode.Length];
                user.QQ_PACKET_00BAVerifyCode.CopyTo(resultArr, 0);
                VerifyCode.CopyTo(resultArr, user.QQ_PACKET_00BAVerifyCode.Length);
                user.QQ_PACKET_00BAVerifyCode = resultArr;
            }
            user.QQ_PACKET_00BAToken = buf.GetByteArray(buf.GetChar());
            buf.GetByteArray(buf.GetChar());
        }
Пример #22
0
        public async Task <IActionResult> VerifyCode(VerifyCode model)
        {
            if (!_accessor.ActionContext.ModelState.IsValid)
            {
                return(new OkObjectResult(model));
            }

            // The following code protects for brute force attacks against the two factor codes.
            // If a user enters incorrect codes for a specified amount of time then the user account
            // will be locked out for a specified amount of time.
            var result = await _signInManager.TwoFactorSignInAsync(model.Provider, model.Code, model.RememberMe, model.RememberBrowser);

            if (result.Succeeded)
            {
                return(RedirectToLocal(model.ReturnUrl));
            }
            if (result.IsLockedOut)
            {
                _logger.LogWarning(7, "User account locked out.");
                return(new OkObjectResult("Lockout"));
            }
            else
            {
                _accessor.ActionContext.ModelState.AddModelError(string.Empty, "Invalid code.");
                return(new OkObjectResult(model));
            }
        }
Пример #23
0
        public JsonResult sendemail(string email)
        {
            var    res = new Result <string>();
            string msg = string.Empty;
            //查看邮箱是否存在
            int id = _memberService.SendEmail(email, out msg);

            if (id > 0)
            {
                Session[Constant.FindPwd] = id;
                //生成验证码
                string code = VerifyCode.GetVerifyCode(6);
                Session[email] = code;
                //发送邮件
                //var send = new EmailUtility(Constant.EmailAccount, Constant.EmailPwd, Constant.Email_smtp, Constant.Email_port);
                //Task.Factory.StartNew(() =>
                //{
                //    send.Send("nsda", email, "找回密码", $"您的验证码是{code}");
                //    _emailLogService.Insert(new EmailLogRequest
                //    {
                //        Account = email,
                //        Content = $"您的验证码是{code}"
                //    });
                //});
                res.flag = true;
                return(Json(res, JsonRequestBehavior.DenyGet));
            }
            else
            {
                res.flag = false;
                res.msg  = msg;
                return(Json(res, JsonRequestBehavior.DenyGet));
            }
        }
Пример #24
0
    protected void Page_Load(object sender, EventArgs e)
    {
        VerifyCode v = new VerifyCode();

        v.Length          = this.length;
        v.FontSize        = this.fontSize;
        v.Chaos           = this.chaos;
        v.BackgroundColor = this.backgroundColor;
        v.ChaosColor      = this.chaosColor;
        v.CodeSerial      = this.codeSerial;
        v.Colors          = this.colors;
        v.Fonts           = this.fonts;
        v.Padding         = this.padding;
        string code = v.CreateVerifyCode();                 //取随机码

        v.CreateImageOnPage(code, this.Context);            // 输出图片

        //  用于验证的Session
        //Session["ValidateCode_Page"] = null;
        //Session["ValidateCode_Page"] = str_ValidateCode;
        // 使用Cookies取验证码的值
        if (LJSheng.Common.LCommon.IsURLName(Request.QueryString["name"]))
        {
            Response.Cookies.Add(new HttpCookie(Request.QueryString["name"], code.ToUpper()));    // 使用Cookies取验证码的值
        }
        else
        {
            Response.Cookies.Add(new HttpCookie("CheckCode", code.ToUpper()));    // 使用Cookies取验证码的值
        }
    }
Пример #25
0
        public ActionResult DeleteConfirmed(long id)
        {
            VerifyCode verifyCode = db.VerifyCodes.Find(id);

            db.VerifyCodes.Remove(verifyCode);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #26
0
        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult GetVerifiedCode()
        {
            string codeStr;

            byte[] arr = new VerifyCode().GetVerifyCode(out codeStr);
            Session.Add("Verifycode", codeStr);
            return(File(arr, @"image/Gif"));
        }
Пример #27
0
        /// <summary>
        /// 验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult GetVerifyCode(string type)
        {
            string code = VerifyCode.CreateRandomCode(4).ToLower();

            LoginUser.Instance.VerificationCode = code;
            byte[] bytes = VerifyCode.CreateImage(code);
            return(File(bytes, @"image/jpeg"));
        }
Пример #28
0
    protected void Page_Load(object sender, EventArgs e)
    {
        VerifyCode vf         = new VerifyCode();
        string     verifyCode = vf.CreateVerifyCode(4);

        Session["verifyCode"] = verifyCode;
        vf.CreateImageOnPage(verifyCode, HttpContext.Current);
    }
Пример #29
0
        public ActionResult GetAuthCode()
        {
            string pic_code = "";

            byte[] b = new VerifyCode().GetVerifyCode(ref pic_code);
            HttpContext.Session.SetString("pic_code", pic_code);//存入session
            return(File(b, @"image/Gif"));
        }
Пример #30
0
        public async Task <ActionResult> GetAuthCode()
        {
            VerifyCode vc = new VerifyCode();

            byte[] content = await vc.GetVerifyCode(HttpContext);

            return(File(content, @"image/Gif"));
        }
Пример #31
0
        public ActionResult GetPicCaptchas()
        {
            var codeMaker = new VerifyCode();

            codeMaker.SetPageNoCache(Response);
            Session["picVerify"] = codeMaker.Paint(Response.OutputStream);
            return(null);
        }
Пример #32
0
 /// <summary>
 /// 产生验证码
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="d">The d.</param>
 /// <returns></returns>
 public ActionResult Vcode(string id, string d)
 {
     VerifyCode v = new VerifyCode();
     string code = v.CreateVerifyCode();                //取随机码
     Session[id] = code;
     v.Padding = 10;
     byte[] bytes = v.CreateImage(code);
     return File(bytes, @"image/jpeg");
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     VerifyCode v = new VerifyCode();
     
     string code = v.CreateVerifyCode(4);//验证码长度
     v.CreateImageOnPage(code, this.Context);
     if (!string.IsNullOrEmpty(Request.QueryString["name"]))
     {
         Session[Request.QueryString["name"].Trim()] = code;
     }
     Session["VerifyCode"] = code;
 }
Пример #34
0
 /// <summary>
 /// 登录验证码
 /// </summary>
 public void VerifyCode_GET()
 {
     string word = null;
     VerifyCode v = new VerifyCode();
     var font = v.GetDefaultFont();
     try
     {
         font = new System.Drawing.Font(font.FontFamily, 16);
         v.AllowRepeat = false;
         Response.BinaryWrite(v.GraphicDrawImage(4,
             VerifyWordOptions.Letter,
             !true,
             font,
             60,
             out word));
     }
     catch
     {
         if (font != null)
         {
             font.Dispose();
         }
     }
     Response.ContentType = "Image/Jpeg";
     VerifyCodeManager.AddWord(word);
 }
Пример #35
0
    protected void Page_Load(object sender, EventArgs e)
    {
        VerifyCode v = new VerifyCode();

        v.Length = this.length;
        v.FontSize = this.fontSize;
        v.Chaos = this.chaos;
        v.BackgroundColor = this.backgroundColor;
        v.ChaosColor = this.chaosColor;
        v.CodeSerial = this.codeSerial;
        v.Colors = this.colors;
        v.Fonts = this.fonts;
        v.Padding = this.padding;
        string code = v.CreateVerifyCode();                //取随机码
        v.CreateImageOnPage(code, this.Context);        // 输出图片

        Response.Cookies.Add(new HttpCookie("CheckCode", code.ToUpper()));// 使用Cookies取验证码的值
    }
Пример #36
0
        public void VerifyImg(string length, string opt,string usefor)
        {
            int _length;                        //验证码长度
            VerifyWordOptions _opt;  //验证码选项
            string verifycode;              //验证码

            if (String.IsNullOrEmpty(length) || !Regex.IsMatch(length, "^\\d+$"))
            {
                _length = 4;
            }
            else
            {
                _length = int.Parse(length);
            }

            if (String.IsNullOrEmpty(opt) || !Regex.IsMatch(opt, "^\\d$"))
            {
                _opt = VerifyWordOptions.Number;
            }
            else
            {
                _opt = (VerifyWordOptions)int.Parse(opt);
            }

            VerifyCode v = new VerifyCode();
            v.AllowRepeat = false;

            //显示验证码
            v.RenderGraphicImage(_length, _opt, true, out verifycode, "Image/Jpeg");

            //保存验证码
             Session["$cms.verifycode"]=verifycode;
        }
Пример #37
0
 /// <summary>
 /// 验证码
 /// </summary>
 public void VerifyImage()
 {
     VerifyCode v = new VerifyCode();
     v.AllowRepeat = false;
     v.DisplayAsVerifyImage(4, VerifyWordOptions.Letter);
 }
Пример #38
0
 /// <summary>
 ///     验证码
 /// </summary>
 /// <param name="context"></param>
 public void VerifyCode(HttpContext context)
 {
     string word = null;
     var v = new VerifyCode();
     var font = v.GetDefaultFont();
     try
     {
         font = new Font(font.FontFamily, 16);
         v.AllowRepeat = false;
         context.Response.BinaryWrite(v.GraphicDrawImage(4,
             VerifyWordOptions.Number,
             !true,
             font,
             30,
             out word));
     }
     catch
     {
         if (font != null)
         {
             font.Dispose();
         }
     }
     context.Response.ContentType = "Image/Jpeg";
     VerifyCodeManager.AddWord(word);
 }
Пример #39
0
 /// <summary>保存验证码</summary>
 public static Guid SaveVerifyCode(string verifyCodeText)
 {
     if(string.IsNullOrWhiteSpace(verifyCodeText)) throw new Exception("输入的验证码不能为空!");
     using (AccountEntities dbContext = new AccountEntities()){
         //CreateTime不可空,虽然有默认值,但Linq要显式传入时间,否则会变成NULL而出错
         VerifyCode verifyCode = new VerifyCode
         {
             VerifyText = verifyCodeText,
             Guid = Guid.NewGuid(),
             CreateTime = DateTime.Now
         };
         dbContext.VerifyCode.Add(verifyCode);
         dbContext.SaveChanges(); //不加Try/Catch的话不会弹出错误
         return verifyCode.Guid;
     }
 }
Пример #40
0
 public ActionResult Vcode(string d,string id = "")
 {
     VerifyCode v = new VerifyCode();
     string code = v.CreateVerifyCode() + "";                //取随机码
     Session[Miaow.function.Helper.SessionNameLogin] = code;
     v.Padding = 10;
     byte[] bytes = v.CreateImage(code);
     return File(bytes, @"image/jpeg");
 }