예제 #1
0
        /// <summary>
        /// 登录验证码
        /// </summary>
        public void VerifyCode_GET()
        {
            if (Cms.RunAtMono)
            {
                return;                // mono下字体无法识别
            }
            string word           = null;
            VerifyCodeGenerator v = new VerifyCodeGenerator();

            try
            {
                FontFamily f    = VerifyCodeGenerator.GetFontFamily();
                Font       font = new Font(f, 16);
                v.AllowRepeat = false;
                Response.BinaryWrite(v.GraphicDrawImage(4,
                                                        VerifyWordOptions.Letter,
                                                        !true,
                                                        font,
                                                        50,
                                                        out word));
                VerifyCodeManager.AddWord(word);
                Response.ContentType = "Image/Jpeg";
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        public void GetVeifyCodeModelTest()
        {
            VerifyCodeManager vcMa = new VerifyCodeManager();

            /*背景是否为图片还是纯色*/
            vcMa.TextConfigM.BackIsImage = true;
            /*背景图片路径(BackIsImage==true时生效)*/
            vcMa.TextConfigM.ImageBackgroundPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"\Content\Images";
            /*背景颜色库(BackIsImage==false时生效)*/
            vcMa.TextConfigM.BackgroundColors.Add(Color.Ivory);
            /*值颜色库*/
            vcMa.TextConfigM.ValueColors.Add(Color.Red);
            /*文本库(AllowRandomChinese==true时失效)*/
            vcMa.TextConfigM.TextLibrary.Add("陈明旭中华人民共和国");
            /*采用随机中文模式*/
            vcMa.TextConfigM.AllowRandomChinese = true;
            /*值数量*/
            vcMa.TextConfigM.ValueCount = 4;
            /*混淆数量*/
            vcMa.TextConfigM.ConfusionCount = 10;
            /*图片大小*/
            vcMa.TextConfigM.ImageSize = new Size(120, 30);
            /*字体大小*/
            vcMa.TextConfigM.FontSize = 18;
            /*获取验证码*/
            VerifyCodeModel vcM = vcMa.GetVeifyCodeModel();

            if (vcM.Images.Count > 0)
            {
                string value = vcM.Value;
                vcM.Images[0].Save(@"D:\Images\Temp\VerifyCode.png");
            }
        }
        public HttpResponseMessage GetValidateCode()
        {
            VerifyCodeManager vcMa = new VerifyCodeManager();

            /*背景是否为图片还是纯色*/
            vcMa.TextConfigM.BackIsImage = true;
            /*背景图片路径(BackIsImage==true时生效)*/
            vcMa.TextConfigM.ImageBackgroundPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"\Images\ValidateCode";
            /*背景颜色库(BackIsImage==false时生效)*/
            vcMa.TextConfigM.BackgroundColors.Add(Color.Ivory);
            /*值颜色库*/
            vcMa.TextConfigM.ValueColors.Add(Color.Red);
            /*文本库(AllowRandomChinese==true时失效)*/
            vcMa.TextConfigM.TextLibrary = new List <string>
            {
                //"abcdefghijklmnopqrstuvwxyz",
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
                "0123456789"
            };
            //vcMa.TextConfigM.TextLibrary.Add("陈明旭中华人民共和国");
            /*采用随机中文模式*/
            vcMa.TextConfigM.AllowRandomChinese = false;
            /*值数量*/
            vcMa.TextConfigM.ValueCount = 4;
            /*混淆数量*/
            vcMa.TextConfigM.ConfusionCount = 10;
            /*混淆模式*/
            vcMa.TextConfigM.ImageObfuscationTypes = new List <VerifyCodeImageObfuscationType>
            {
                /*假值混淆*/
                VerifyCodeImageObfuscationType.FalseValue,
                /*条纹混淆*/
                VerifyCodeImageObfuscationType.Stripe
            };
            /*图片大小*/
            vcMa.TextConfigM.ImageSize = new Size(120, 30);
            /*字体大小*/
            vcMa.TextConfigM.FontSize = 18;
            /*获取验证码*/
            VerifyCodeModel vcM = vcMa.GetVeifyCodeModel();

            if (vcM.Images.Count > 0)
            {
                /*验证码的值存入缓存中*/
                WebCacheManager.Set(ApplicationManager.VALIDATECODEKEY + vcM.Value, vcM.Value, DateTimeOffset.Now.AddMinutes(5));
                using (MemoryStream ms = new MemoryStream())
                {
                    vcM.Images[0].Save(ms, ImageFormat.Jpeg);
                    HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new ByteArrayContent(ms.ToArray())
                    };
                    result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
                    return(result);
                }
            }
            return(null);
        }
예제 #5
0
        /// <summary>
        /// 登录验证码
        /// </summary>
        public void VerifyCode()
        {
            string word = null;
            var    v    = new VerifyCodeGenerator();

            Response.ContentType("Image/Jpeg");
            var f    = GetCodeFontFamily();
            var font = new Font(f, 16);

            v.AllowRepeat = false;
            var code = v.GenerateVerifyWords(4, VerifyWordOptions.Letter);

            Response.WriteAsync(v.GraphicDrawImage(code, !true, font, 50));
            VerifyCodeManager.AddWord(new string(code));
        }
예제 #6
0
        /// <summary>
        /// 登录提交
        /// </summary>
        public void Login_POST()
        {
            string username   = base.Request.Form["uid"].Trim(),
                   password   = base.Request.Form["pwd"].Trim(),
                   verifycode = base.Request.Form["code"].Trim();

            if (!Cms.RunAtMono)
            {
                if (verifycode == "" || !VerifyCodeManager.Compare(verifycode))
                {
                    base.RenderError("验证码不正确");
                    return;
                }
            }

            int tag = UserState.Administrator.Login(username, password, 3600 * 120);

            if (tag == -1)
            {
                base.RenderError("账户或密码不正确!");
            }
            else if (tag == -2)
            {
                base.RenderError("账号已被停用,请联系管理员!");
            }
            else
            {
                base.RenderSuccess();
                //保存登陆信息
            }

            //设置站点
            //                UserBll usr = CmsLogic.UserBll.GetUser(username, password);
            //
            //                if (usr != null)
            //                {
            //                    CmsLogic.UserBll.UpdateUserLastLoginDate(username);
            //
            //                    if (!usr.Enabled)
            //                    {
            //                        base.RenderError("账号已被停用,请联系管理员!");
            //                    }
            //                    else
            //                    {
            //                        //保存登陆信息
            //                        bool result = UserState.Administrator.Login(username, password, 3600 * 120);
            //
            //                        //验证站点信息
            //                        if (usr.SiteId > 0)
            //                        {
            //                            SiteDto site = SiteCacheManager.GetSite(usr.SiteId);
            //                            if (!(site.SiteId > 0))
            //                            {
            //                                base.RenderError("账号已被停用,请联系管理员!");
            //                                return;
            //                            }
            //                            base.CurrentSite = site;
            //                        }
            //                        base.RenderSuccess();
            //                    }
            //}
            //else
            // {
            //   base.RenderError("账户或密码不正确!");
            //}
        }