Ejemplo n.º 1
0
        public static AnswerAndDate ParseAnswerAndDate(string encryptedAnswer, int timeoutInSeconds)
        {
            AnswerAndDate answerAndDate;

            answerAndDate._expired = false;
            answerAndDate._answer  = string.Empty;
            answerAndDate._date    = DateTime.MinValue;

            if (String.IsNullOrEmpty(encryptedAnswer))
            {
                return(answerAndDate);
            }

            string decryptedAnswer = CaptchaBase.DecryptString(encryptedAnswer);

            string[] answerParts = decryptedAnswer.Split('|');
            if (answerParts.Length < 2)
            {
                return(answerAndDate);
            }

            answerAndDate._answer = answerParts[0];
            answerAndDate._date   = DateTime.ParseExact(answerParts[1], "yyyy/MM/dd HH:mm", CultureInfo.InvariantCulture);

            if (timeoutInSeconds != 0 && (DateTime.Now - answerAndDate._date).TotalSeconds >= timeoutInSeconds)
            {
                throw new CaptchaExpiredException(Resources.CaptchaExpired_WaitedTooLong);
            }

            return(answerAndDate);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a base 64 encrypted serialized representation of this object.
        /// </summary>
        /// <returns></returns>
        public string ToEncryptedString()
        {
            if (Width == 0)
            {
                Width = 180;
            }

            if (Height == 0)
            {
                Height = 50;
            }

            return(CaptchaBase.EncryptString(ToString()));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reconstructs an instance of this type from an encrypted serialized string.
        /// </summary>
        /// <param name="encrypted"></param>
        public static CaptchaInfo FromEncryptedString(string encrypted)
        {
            string decrypted = CaptchaBase.DecryptString(encrypted);

            string[] values = decrypted.Split('|');

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

            return(info);
        }