Exemple #1
0
        public static string ReStr(string paraName)
        {
            string str = HttpContext.Current.Request.Params[paraName];

            if (str == null)
            {
                throw new Exception("" + paraName + "参数获取为null");
            }

            if (SqlFilter2(str))
            {
                throw new Exception("危险字符串:" + str + "");
            }

            if (paraName == "para")  //ajax请求开始
            {
                string s = ReStr("s", "web");
                if (s == "app")
                {
                    string GetMemberId = ReStr("GetMemberId");
                    CookieSings.AddCookieStr("CurrentMemberId", JiaMi.encMe(GetMemberId));
                }
            }



            return(System.Web.HttpUtility.UrlDecode(str));
        }
Exemple #2
0
        /// <summary>
        /// 绘制验证码
        /// </summary>
        public void CreateImage()
        {
            int int_ImageWidth = this.text.Length * letterWidth;

            CookieSings.AddCookieStr("yzm", this.text);
            Bitmap   image = new Bitmap(int_ImageWidth, letterHeight);
            Graphics g     = Graphics.FromImage(image);

            g.Clear(Color.White);
            for (int i = 0; i < 2; i++)
            {
                int x1 = Next(image.Width - 1);
                int x2 = Next(image.Width - 1);
                int y1 = Next(image.Height - 1);
                int y2 = Next(image.Height - 1);
                g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
            }
            int _x = -12, _y = 0;

            for (int int_index = 0; int_index < this.text.Length; int_index++)
            {
                _x += Next(12, 16);
                _y  = Next(-2, 2);
                string str_char = this.text.Substring(int_index, 1);
                str_char = Next(1) == 1 ? str_char.ToLower() : str_char.ToUpper();
                Brush newBrush = new SolidBrush(GetRandomColor());
                Point thePos   = new Point(_x, _y);
                g.DrawString(str_char, fonts[Next(fonts.Length - 1)], newBrush, thePos);
            }
            for (int i = 0; i < 10; i++)
            {
                int x = Next(image.Width - 1);
                int y = Next(image.Height - 1);
                image.SetPixel(x, y, Color.FromArgb(Next(0, 255), Next(0, 255), Next(0, 255)));
            }
            image = TwistImage(image, true, Next(1, 3), Next(4, 6));
            g.DrawRectangle(new Pen(Color.LightGray, 1), 0, 0, int_ImageWidth - 1, (letterHeight - 1));
            this.image = image;
            System.IO.MemoryStream memoryStream = new MemoryStream();
            image.Save(memoryStream, ImageFormat.Jpeg);
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.ContentType = "image/gif";
            HttpContext.Current.Response.BinaryWrite(memoryStream.ToArray());
            image.Dispose();
            HttpContext.Current.Response.End();
        }
Exemple #3
0
        /// <summary>
        /// 以默认的大小和默认的字符个数产生图片
        /// </summary>
        /// <returns></returns>
        public Image GetImage()
        {
            Bitmap   image = new Bitmap(width, height);
            Graphics g     = Graphics.FromImage(image);

            g.Clear(Color.White);

            Random random     = new Random();
            string randString = GetMix(random);
//            do
//            {
////使用DateTime.Now.Millisecond作为生成随机数的参数,增加随机性
//                randString += RandCharString.Substring(random.Next(DateTime.Now.Millisecond)%RandCharString.Length, 1);
//            }
//            while (randString.Length < 4);
            float emSize = (float)width / randString.Length;
            Font  font   = new Font("Arial", emSize, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
            Pen   pen    = new Pen(Color.Silver);

            #region 画图片的背景噪音线
            int x1, y1, x2, y2;

            for (int i = 0; i < 25; i++)
            {
                x1 = random.Next(image.Width);
                y1 = random.Next(image.Height);
                x2 = random.Next(image.Width);
                y2 = random.Next(image.Height);
                g.DrawLine(pen, x1, y1, x2, y2);
            }
            #endregion

            #region 画图片的前景噪音点
            for (int i = 0; i < 100; i++)
            {
                x1 = random.Next(image.Width);
                y1 = random.Next(image.Height);
                image.SetPixel(x1, y1, Color.FromArgb(random.Next(Int32.MaxValue)));
            }
            #endregion
            CookieSings.AddCookieStr("yzm", randString);
            g.DrawString(randString, font, Brushes.Blue, 2, 2);

            g.Dispose();
            return(image);
        }