Subtext.Web.Controls.Captcha.CaptchaInfo.FromEncryptedString C# (CSharp) Method

FromEncryptedString() public static method

Reconstructs an instance of this type from an encrypted serialized string.
public static FromEncryptedString ( string encrypted ) : CaptchaInfo
encrypted string
return CaptchaInfo
        public static CaptchaInfo FromEncryptedString(string encrypted)
        {
            string decrypted = CaptchaBase.DecryptString(encrypted);
            string[] values = decrypted.Split('|');

            CaptchaInfo info = new CaptchaInfo();
            info.Width = int.Parse(values[0]);
            info.Height = int.Parse(values[1]);
            info.WarpFactor = (CaptchaImage.FontWarpFactor)Enum.Parse(typeof(CaptchaImage.FontWarpFactor), values[2]);
            info.FontFamily = values[3];
            info.Text = values[4];
            info.DateGenerated = DateTime.ParseExact(values[5], "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
            return info;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Renders the Captcha Image.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"></see> object that provides
        /// references to the intrinsic server objects (for example, Request, Response, Session, and Server)
        /// used to service HTTP requests.</param>
        public void ProcessRequest(HttpContext context)
        {
            HttpApplication application          = context.ApplicationInstance;
            string          encryptedCaptchaInfo = application.Request.QueryString["spec"];
            CaptchaInfo     captcha = CaptchaInfo.FromEncryptedString(encryptedCaptchaInfo);

            string textToRender = captcha.Text;

            if (string.IsNullOrEmpty(textToRender))
            {
                application.Response.StatusCode = 404;
                application.Response.End();
            }
            else
            {
                using (var captchaImage = new CaptchaImage())
                {
                    captchaImage.Width    = captcha.Width;
                    captchaImage.Height   = captcha.Height;
                    captchaImage.FontWarp = captcha.WarpFactor;
                    captchaImage.Font     = captcha.FontFamily;
                    captchaImage.Text     = textToRender;
                    captchaImage.Image.Save(application.Context.Response.OutputStream, ImageFormat.Jpeg);
                }
                application.Response.ContentType = "image/jpeg";
                application.Response.StatusCode  = 200;
                application.Response.End();
            }
        }