예제 #1
0
        public IActionResult GetCode()
        {
            //待返回对象
            var result = new ResponseModel(ResponseCode.Success, "查询成功!");

            //调用图片码
            string randomCode = SecurityCode.CreateRandomCode(4);

            if (!string.IsNullOrEmpty(randomCode))
            {
                //字符串加缓存
                string   keys = "ImageCode_Login" + DateTime.Now.ToString("yyyyMMddHHmmssfffffff");//Guid.NewGuid()
                TimeSpan ts1  = new TimeSpan(0, 5, 0);
                CacheManager.Create().Set(keys, randomCode, ts1);
                //读取图片
                byte[] imgCode   = SecurityCode.CreateValidateGraphic(randomCode);
                string base64str = Convert.ToBase64String(imgCode);

                var ImagCode = new
                {
                    imgcode = "data:image/png;base64," + base64str,
                    imgkey  = keys,
                };
                result.data = ImagCode;
            }
            return(Json(result));
        }
예제 #2
0
 /// <summary>
 /// 发送邮件验证码
 /// </summary>
 public ActionResult SendEmail1(string mailTo, string mailSubject, string mailContent)
 {
     try
     {
         //验证码
         SecurityCode scode = new SecurityCode();
         string       code  = scode.CreateRandomCode(5);
         Session["code"] = code;
         SmtpClient mailClient = new SmtpClient("smtp.qq.com");
         mailClient.EnableSsl             = true;
         mailClient.UseDefaultCredentials = false;
         //Credentials登陆SMTP服务器的身份验证.
         mailClient.Credentials = new NetworkCredential("*****@*****.**", "aiookfzkwekjijif");              //邮箱,
         MailMessage message = new MailMessage(new MailAddress("*****@*****.**"), new MailAddress(mailTo)); //发件人,收件人
         message.IsBodyHtml = true;
         message.Body       = mailContent + ":" + code;                                                        //邮件内容
         message.Subject    = mailSubject;                                                                     //邮件主题
         mailClient.Send(message);                                                                             // 发送邮件
         return(Json(new { date = "已发送,请查收", type = 1 }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception e)
     {
         return(Json(new { date = "发送失败:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet));
     }
 }
예제 #3
0
        public ActionResult GetSecurityCode()
        {
            SecurityCode code = new SecurityCode();

            Session["skey"] = code.CreateRandomCode(4);
            byte[] buf = code.CreateValidateGraphic(Session["skey"].ToString());
            return(File(buf, "image/Jpeg"));
        }
예제 #4
0
        public ActionResult SecurityCode()
        {
            SecurityCode sc      = new SecurityCode();
            string       oldcode = TempData["SecurityCode"] as string;
            string       code    = sc.CreateRandomCode(5);

            TempData["SecurityCode"] = code;
            return(File(sc.CreateValidateGraphic(code), "image/Jpeg"));
        }