Пример #1
0
        /// <summary>
        /// Creates an audio stream bases on <see cref="Tenor.Security.Captcha"/> on session state.
        /// </summary>
        private void CaptchaAudioRequest(string captchaSessionState)
        {
            if (HttpContext.Current == null)
            {
                throw new InvalidContextException();
            }
            HttpSessionState session = HttpContext.Current.Session;

            if (session == null)
            {
                throw new InvalidContextException();
            }

            Tenor.Security.Captcha cap = session[captchaSessionState] as Tenor.Security.Captcha;
            if (cap == null)
            {
                cap = new Tenor.Security.Captcha();
                session[captchaSessionState] = cap;
            }

            MemoryStream mem = new MemoryStream(cap.GenerateAudio());

            CacheData dados = new CacheData();

            dados.ContentType   = "audio/x-wav";
            dados.Expires       = 0;
            dados.ContentLength = mem.Length;
            dados.FileName      = "captcha.wav";

            WriteHeaders(HttpContext.Current.ApplicationInstance, dados);
            WriteStream(mem, HttpContext.Current.ApplicationInstance);
        }
Пример #2
0
        /// <summary>
        /// Draws a captcha image based on <see cref="Tenor.Security.Captcha"/> on session state.
        /// </summary>
        private void CaptchaRequest(string captchaSessionState)
        {
            if (HttpContext.Current == null)
            {
                throw new InvalidContextException();
            }
            HttpSessionState session = HttpContext.Current.Session;

            if (session == null)
            {
                throw new InvalidContextException();
            }

            Tenor.Security.Captcha cap = session[captchaSessionState] as Tenor.Security.Captcha;
            if (cap == null)
            {
                cap = new Tenor.Security.Captcha();
                session[captchaSessionState] = cap;
            }

            MemoryStream mem = new MemoryStream();

            cap.GenerateImage().Save(mem, System.Drawing.Imaging.ImageFormat.Jpeg);

            CacheData dados = new CacheData();

            dados.ContentType   = "image/jpeg";
            dados.Expires       = 0;
            dados.ContentLength = mem.Length;
            dados.FileName      = "captcha.jpg";

            WriteHeaders(HttpContext.Current.ApplicationInstance, dados);
            WriteStream(mem, HttpContext.Current.ApplicationInstance);
        }