Ejemplo n.º 1
0
        /// <Summary>Gets the next Captcha</Summary>
        protected virtual string GetNextCaptcha()
        {
            StringBuilder sb     = new StringBuilder();
            Random        random = new Random();

            int intMaxLength = CaptchaChars.Length - 1;

            for (int n = 0; n < CaptchaLength; n++)
            {
                sb.Append(CaptchaChars.Substring(random.Next(intMaxLength), 1));
            }
            return(sb.ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the next Captcha
        /// </summary>
        /// <history>
        ///     [cnurse]	03/17/2006	created
        /// </history>
        protected virtual string GetNextCaptcha()
        {
            var sb   = new StringBuilder();
            var rand = new Random();
            int n;
            var intMaxLength = CaptchaChars.Length;

            for (n = 0; n <= CaptchaLength - 1; n++)
            {
                sb.Append(CaptchaChars.Substring(rand.Next(intMaxLength), 1));
            }
            return(sb.ToString());
        }
        /// <summary>
        /// Gets the next Captcha
        /// </summary>
        /// <history>
        ///     [cnurse]	03/17/2006	created
        /// </history>
        protected virtual string GetNextCaptcha()
        {
            var sb   = new StringBuilder();
            var rand = new Random();
            int n;
            var intMaxLength = CaptchaChars.Length;

            for (n = 0; n <= CaptchaLength - 1; n++)
            {
                sb.Append(CaptchaChars.Substring(rand.Next(intMaxLength), 1));
            }
            var challenge = sb.ToString();

            var cacheKey = string.Format(DataCache.CaptchaCacheKey, challenge);

            DataCache.SetCache(cacheKey, challenge, TimeSpan.FromMinutes(2));
            return(challenge);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the next Captcha
        /// </summary>
        protected virtual string GetNextCaptcha()
        {
            var sb   = new StringBuilder();
            var rand = new Random();
            int n;
            var intMaxLength = CaptchaChars.Length;

            for (n = 0; n <= CaptchaLength - 1; n++)
            {
                sb.Append(CaptchaChars.Substring(rand.Next(intMaxLength), 1));
            }
            var challenge = sb.ToString();

            //NOTE: this could be a problem in a web farm using in-memory caching where
            // the request might go to another server in the farm. Also, in a system
            // with a single server or web-farm, the cache might be cleared
            // which will cause a problem in such case unless sticky sessions are used.
            var cacheKey = string.Format(DataCache.CaptchaCacheKey, challenge);

            DataCache.SetCache(cacheKey, challenge, (DNNCacheDependency)null, DateTime.Now.AddSeconds(_Expiration + 1),
                               Cache.NoSlidingExpiration, CacheItemPriority.AboveNormal, null);
            return(challenge);
        }