Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int    MyLen     = 4;
            string EmailText = "none";
            SizeF  size;
            float  fontSize = (float)System.Convert.ToSingle(ConfigurationManager.AppSettings["EmailImageFontSize"].ToString());
            Font   font;

            font = new Font(ConfigurationManager.AppSettings["EmailImageFontFamilyName"].ToString(), fontSize, FontStyle.Regular);

            // fix this
            if (((string)Session["EmailImgText"]).Length > 0)
            {
                MyLen     = ((string)Session["EmailImgText"]).Length;
                EmailText = (string)Session["EmailImgText"];
            }
            // Create a new 32-bit bitmap image.
            Bitmap bitmap = new Bitmap(MyLen, 25, PixelFormat.Format32bppArgb);

            // Create a graphics object for drawing.
            Graphics g = Graphics.FromImage(bitmap);

            g.SmoothingMode = SmoothingMode.AntiAlias;

            size = g.MeasureString(EmailText, font);
            Session["EmailImgWidth"]  = size.Width;
            Session["EmailImgHeight"] = size.Height;

            // Create a CAPTCHA image using the text stored in the Session object.
            EmailImg.TextImage ci = new EmailImg.TextImage(EmailText, (int)size.Width, (int)size.Height,
                                                           ConfigurationManager.AppSettings["EmailImageFontFamilyName"].ToString());

            // Change the response headers to output a JPEG image.
            Response.Clear();
            Response.ContentType = "image/jpeg";

            // Code to stop image from being cached
            Response.CacheControl = "no-cache";
            Response.AddHeader("Pragma", "no-cache");
            Response.Expires = -1;
            Response.AddHeader("Last-Modified", DateTime.Now.ToString());

            // Write the image to the response stream in JPEG format.
            ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg);

            // Dispose of the CAPTCHA image object.
            ci.Dispose();

            font.Dispose();
            g.Dispose();
        } //ends page load
Ejemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            // Set up the response settings
            context.Response.ContentType = "image/bmp";
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.BufferOutput = false;

            if (!string.IsNullOrEmpty(context.Request.QueryString["msg"]))
            {
                Utilities.DataIO data = new Profiles.Profile.Utilities.DataIO();
                SqlDataReader    reader;
                string           email = context.Request.QueryString["msg"];

                SqlCommand cmd = new SqlCommand("SELECT [Utility.Application].[fnDecryptBase64RC4] ( '" + email + "',   (Select [value] from [Framework.].parameter with(nolock) where ParameterID = 'RC4EncryptionKey'))");
                reader = data.GetSQLDataReader(cmd);
                reader.Read();

                string EmailText = reader[0].ToString();

                int MyLen;

                SizeF size;
                float fontSize = 11;
                Font  font;

                font = new Font("Arial", fontSize, FontStyle.Regular);


                MyLen = EmailText.Length;


                // Create a new 32-bit bitmap image.
                Bitmap bitmap = new Bitmap(MyLen, 25, PixelFormat.Format32bppArgb);

                // Create a graphics object for drawing.
                Graphics g = Graphics.FromImage(bitmap);
                g.SmoothingMode = SmoothingMode.AntiAlias;

                size = g.MeasureString(EmailText, font);

                // Create a CAPTCHA image using the text stored in the Session object.
                EmailImg.TextImage ci = new EmailImg.TextImage(EmailText, (int)size.Width, (int)size.Height, "Arial");

                // Change the response headers to output a JPEG image.
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ContentType = "image/jpeg";

                // Code to stop image from being cached
                HttpContext.Current.Response.CacheControl = "no-cache";
                HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
                HttpContext.Current.Response.Expires = -1;
                HttpContext.Current.Response.AddHeader("Last-Modified", DateTime.Now.ToString());

                // Write the image to the response stream in JPEG format.
                ci.Image.Save(HttpContext.Current.Response.OutputStream, ImageFormat.Jpeg);

                // Dispose of the CAPTCHA image object.
                ci.Dispose();

                font.Dispose();
                g.Dispose();
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            // Set up the response settings
            context.Response.ContentType = "image/bmp";
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.BufferOutput = false;

            if (!string.IsNullOrEmpty(context.Request.QueryString["msg"]))
            {
                Utilities.DataIO data = new Profiles.Profile.Utilities.DataIO();
                SqlDataReader reader;
                string email = context.Request.QueryString["msg"];

                SqlCommand cmd = new SqlCommand("SELECT [Utility.Application].[fnDecryptBase64RC4] ( '" + email + "',   (Select [value] from [Framework.].parameter with(nolock) where ParameterID = 'RC4EncryptionKey'))");
                reader = data.GetSQLDataReader(cmd);
                reader.Read();

                string EmailText = reader[0].ToString();

                int MyLen;

                SizeF size;
                float fontSize = 13;
                Font font;

                font = new Font("Arial", fontSize, FontStyle.Regular);

                MyLen = EmailText.Length;

                // Create a new 32-bit bitmap image.
                Bitmap bitmap = new Bitmap(MyLen, 25, PixelFormat.Format32bppArgb);

                // Create a graphics object for drawing.
                Graphics g = Graphics.FromImage(bitmap);
                g.SmoothingMode = SmoothingMode.AntiAlias;

                size = g.MeasureString(EmailText, font);

                // Create a CAPTCHA image using the text stored in the Session object.
                EmailImg.TextImage ci = new EmailImg.TextImage(EmailText, (int)size.Width, (int)size.Height, "Arial");

                // Change the response headers to output a JPEG image.
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ContentType = "image/jpeg";

                // Code to stop image from being cached
                HttpContext.Current.Response.CacheControl = "no-cache";
                HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
                HttpContext.Current.Response.Expires = -1;
                HttpContext.Current.Response.AddHeader("Last-Modified", DateTime.Now.ToString());

                // Write the image to the response stream in JPEG format.
                ci.Image.Save(HttpContext.Current.Response.OutputStream, ImageFormat.Jpeg);

                // Dispose of the CAPTCHA image object.
                ci.Dispose();

                font.Dispose();
                g.Dispose();

            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int MyLen = 4;
            string EmailText = "none";
            SizeF size;
            float fontSize = (float)System.Convert.ToSingle(ConfigurationManager.AppSettings["EmailImageFontSize"].ToString());
            Font font;

            font = new Font(ConfigurationManager.AppSettings["EmailImageFontFamilyName"].ToString(), fontSize, FontStyle.Regular);

            // fix this
            if (((string)Session["EmailImgText"]).Length > 0)
            {
                MyLen = ((string)Session["EmailImgText"]).Length;
                EmailText = (string)Session["EmailImgText"];
            }
            // Create a new 32-bit bitmap image.
            Bitmap bitmap = new Bitmap(MyLen, 25, PixelFormat.Format32bppArgb);

            // Create a graphics object for drawing.
            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            size = g.MeasureString(EmailText, font);
            Session["EmailImgWidth"] = size.Width;
            Session["EmailImgHeight"] = size.Height;

            // Create a CAPTCHA image using the text stored in the Session object.
            EmailImg.TextImage ci = new EmailImg.TextImage(EmailText, (int)size.Width, (int)size.Height,
                ConfigurationManager.AppSettings["EmailImageFontFamilyName"].ToString());

            // Change the response headers to output a JPEG image.
            Response.Clear();
            Response.ContentType = "image/jpeg";

            // Code to stop image from being cached
            Response.CacheControl = "no-cache";
            Response.AddHeader("Pragma", "no-cache");
            Response.Expires = -1;
            Response.AddHeader("Last-Modified", DateTime.Now.ToString());

            // Write the image to the response stream in JPEG format.
            ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg);

            // Dispose of the CAPTCHA image object.
            ci.Dispose();

            font.Dispose();
            g.Dispose();
        }