コード例 #1
0
        public ActionResult GetCaptcha()
        {
            var randomText = captchaBLL.GenerateRandomText(4);

            CaptchaHash = captchaBLL.ComputeMd5Hash(randomText);
            return(File(captchaBLL.GenerateCaptchaImage(randomText), "image/gif"));
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Captcha1.ImageStyle = BotDetect.ImageStyle.Negative;
            //Captcha1.CustomDarkColor = Color.White;
            //Captcha1.CustomLightColor = Color.FromArgb(72, 72, 72);

            if (Page.IsPostBack)
            {
                // validate the Captcha to check we're not dealing with a bot
                //bool isHuman = Captcha1.Validate(CaptchaControl1.Text);

                //CaptchaControl1.Text = null; // clear previous user input

                //if (!isHuman)
                //{
                //    // TODO: Captcha validation failed, show error message
                //    Label_ErrorMsg.Text = "驗證碼錯誤!";
                //}
                //else
                //{
                //    // TODO: Captcha validation passed, proceed with protected action
                //    //MvcCaptcha.ResetCaptcha("ExampleCaptcha");
                //    Label_ErrorMsg.Text = "";
                //}


                bool isHuman = Session["CAPTCHA"].ToString().Equals(CaptchaControl1.Text);

                CaptchaControl1.Text = null; // clear previous user input

                if (!isHuman)
                {
                    // TODO: Captcha validation failed, show error message
                    Label_ErrorMsg.Text = "驗證碼錯誤!";
                }
                else
                {
                    // TODO: Captcha validation passed, proceed with protected action
                    //MvcCaptcha.ResetCaptcha("ExampleCaptcha");
                    Label_ErrorMsg.Text = "";
                }
                CaptchaBLL captchaBll = new CaptchaBLL();
                string     captcha    = captchaBll.GenerateRandomText(5);
                byte[]     arr        = captchaBll.GenerateCaptchaImage(captcha);

                Session["CAPTCHA"] = captcha;
                Image1.ImageUrl    = "data:image;base64," + Convert.ToBase64String(arr);
                CaptchaCode.Text   = captcha;
            }
            else
            {
                CaptchaBLL captchaBll = new CaptchaBLL();
                string     captcha    = captchaBll.GenerateRandomText(5);
                byte[]     arr        = captchaBll.GenerateCaptchaImage(captcha);
                Session["CAPTCHA"] = captcha;
                Image1.ImageUrl    = "data:image/png;base64," + Convert.ToBase64String(arr);
                CaptchaCode.Text   = captcha;
            }
        }
コード例 #3
0
        public ActionResult GetCaptcha()
        {
            // 隨機產生四個字元
            var randomText = captchaBLL.GenerateRandomText(4);

            // 加密後存在 Session,也可以不用加密,比對時一致就好。
            CaptchaHash = randomText;
            //CaptchaHash = captchaBLL.ComputeMd5Hash(randomText);
            // 回傳 gif 圖檔
            return(File(captchaBLL.GenerateCaptchaImage(randomText), "image/gif"));
        }