コード例 #1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            bool valid = false;

            var formData = filterContext.HttpContext.Request.Unvalidated.Form;
            var captchaChallengeValue = formData[CHALLENGE_FIELD_KEY];
            var captchaResponseValue = formData[RESPONSE_FIELD_KEY];

            if (!string.IsNullOrEmpty(captchaChallengeValue) && !string.IsNullOrEmpty(captchaResponseValue))
            {
                var captchaSettings = EngineContext.Current.Resolve<CaptchaSettings>();
                if (captchaSettings.Enabled)
                {
                    // validate captcha
                    var captchaValidtor = new RecaptchaValidator
                    {
                        PrivateKey = captchaSettings.ReCaptchaPrivateKey,
                        RemoteIP = filterContext.HttpContext.Request.UserHostAddress,
                        Challenge = captchaChallengeValue,
                        Response = captchaResponseValue
                    };

                    var recaptchaResponse = captchaValidtor.Validate();
                    valid = recaptchaResponse.IsValid;
                }
            }

            //this will push the result value into a parameter in our Action
            filterContext.ActionParameters[CAPTCHA_VALID] = valid;
        }
コード例 #2
0
        /// <summary>
        /// Perform validation of reCAPTCHA.
        /// </summary>
        public void Validate()
        {
            if (Page.IsPostBack && Visible && Enabled && (GetHiddenFieldControl().Value != "offline") && !_skipRecaptcha)
            {
                if (_recaptchaResponse == null)
                {
                    if (Visible && Enabled)
                    {
                        RecaptchaValidator validator = new RecaptchaValidator
                        {
                            SecretKey = SecretKey,
                            Response  = Context.Request.Form[RecaptchaResponseField]
                        };

                        _recaptchaResponse = validator.Response == null
                            ? RecaptchaResponse.InvalidResponse
                            : validator.Validate();
                    }
                }
            }
            else
            {
                _recaptchaResponse = RecaptchaResponse.Valid;
            }
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var captchaChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
            var captchaResponseValue = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
            var captchaValidtor = new RecaptchaValidator
                                      {
                                          PrivateKey = ConfigurationManager.AppSettings["recaptcha.key.private"],
                                          RemoteIP = filterContext.HttpContext.Request.UserHostAddress,
                                          Challenge = captchaChallengeValue,
                                          Response = captchaResponseValue
                                      };

            var recaptchaResponse = captchaValidtor.Validate();

            // this will push the result value into a parameter in our Action  
            filterContext.ActionParameters["captchaValid"] = recaptchaResponse.IsValid;

            //add validation
            if (!recaptchaResponse.IsValid)
            {
                filterContext.Controller.ViewData.ModelState.AddModelError(_markerProperty, _validationMessage);
            }


            base.OnActionExecuting(filterContext);
        }
コード例 #4
0
ファイル: AccountController.cs プロジェクト: FoundOPS/server
        private bool PerformRecaptcha()
        {
            var validator = new RecaptchaValidator
            {
                PrivateKey = "<6LeMMMYSAAAAAP0q9WGcmrIO3KsRbct-O6KyL4r6>",
                RemoteIP = Request.UserHostAddress,
                Response = Request.Form["recaptcha_response_field"],
                Challenge = Request.Form["recaptcha_challenge_field"]
            };

            try
            {
                var validationResult = validator.Validate();

                if (validationResult.ErrorMessage == "incorrect-captcha-sol")
                    ModelState.AddModelError("PassReCaptcha", string.Format("Please retry the ReCaptcha portion again."));

                return validationResult.IsValid;
            }
            catch (Exception)
            {
                ModelState.AddModelError("PassReCaptcha", "an error occured with ReCaptcha please consult documentation.");
                return false;
            }
        }
コード例 #5
0
        /// <summary>
        /// Perform validation of reCAPTCHA.
        /// </summary>
        public void Validate()
        {
            if (Page.IsPostBack && Visible && Enabled && !this.skipRecaptcha)
            {
                if (this.recaptchaResponse == null)
                {
                    if (Visible && Enabled)
                    {
                        RecaptchaValidator validator = new RecaptchaValidator();
                        validator.PrivateKey = this.PrivateKey;
                        validator.RemoteIP   = Page.Request.UserHostAddress;
                        validator.Challenge  = Context.Request.Form[RECAPTCHA_CHALLENGE_FIELD];
                        validator.Response   = Context.Request.Form[RECAPTCHA_RESPONSE_FIELD];
                        validator.Proxy      = this.proxy;

                        if (validator.Challenge == null)
                        {
                            this.recaptchaResponse = RecaptchaResponse.InvalidChallenge;
                        }
                        else if (validator.Response == null)
                        {
                            this.recaptchaResponse = RecaptchaResponse.InvalidResponse;
                        }
                        else
                        {
                            this.recaptchaResponse = validator.Validate();
                        }
                    }
                }
            }
            else
            {
                this.recaptchaResponse = RecaptchaResponse.Valid;
            }
        }
コード例 #6
0
        public static bool Validate(HttpContextBase context)
        {
            var request = context.Request;

            var validator = new RecaptchaValidator
            {
                PrivateKey = ConfigurationManager.AppSettings["ReCaptchaPrivateKey"],
                RemoteIP = request.UserHostAddress,
                Challenge = request.Form[ChallengeFieldKey],
                Response = request.Form[ResponseFieldKey]
            };
            RecaptchaResponse response = validator.Validate();
            return response.IsValid;
        }
コード例 #7
0
ファイル: Captcha.cs プロジェクト: vibhutisuthar/TEST
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var captchaChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
            var captchaResponseValue = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
            var captchaValidtor = new Recaptcha.RecaptchaValidator
                                      {
                                          PrivateKey = PRIVATE_KEY,
                                          RemoteIP = filterContext.HttpContext.Request.UserHostAddress,
                                          Challenge = captchaChallengeValue,
                                          Response = captchaResponseValue
                                      };

            var recaptchaResponse = captchaValidtor.Validate();

            // this will push the result value into a parameter in our Action
            filterContext.ActionParameters["captchaValid"] = recaptchaResponse.IsValid;

            base.OnActionExecuting(filterContext);
        }
コード例 #8
0
ファイル: Captcha.cs プロジェクト: vibhutisuthar/TEST
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var captchaChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
            var captchaResponseValue  = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
            var captchaValidtor       = new Recaptcha.RecaptchaValidator
            {
                PrivateKey = PRIVATE_KEY,
                RemoteIP   = filterContext.HttpContext.Request.UserHostAddress,
                Challenge  = captchaChallengeValue,
                Response   = captchaResponseValue
            };

            var recaptchaResponse = captchaValidtor.Validate();

            // this will push the result value into a parameter in our Action
            filterContext.ActionParameters["captchaValid"] = recaptchaResponse.IsValid;

            base.OnActionExecuting(filterContext);
        }
コード例 #9
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (RoadkillSettings.IsRecaptchaEnabled)
            {
                string challengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_KEY];
                string responseValue = filterContext.HttpContext.Request.Form[RESPONSE_KEY];

                RecaptchaValidator validator = new RecaptchaValidator();
                validator.PrivateKey = RoadkillSettings.RecaptchaPrivateKey;
                validator.RemoteIP = filterContext.HttpContext.Request.UserHostAddress;
                validator.Challenge = challengeValue;
                validator.Response = responseValue;

                RecaptchaResponse validationResponse = validator.Validate();
                filterContext.ActionParameters["isCaptchaValid"] = validationResponse.IsValid;
            }

            base.OnActionExecuting(filterContext);
        }
コード例 #10
0
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     string captchaChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
     if (string.IsNullOrEmpty(captchaChallengeValue))
     {
         filterContext.ActionParameters["captchaValid"] = true;
     }
     else
     {
         string captchaResponseValue = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
         RecaptchaResponse recaptchaResponse = new RecaptchaValidator
         {
             PrivateKey = "6Lfvw8ISAAAAAPj5Xlu-DZ7EPF21bvzB3z65STHr",
             RemoteIP = filterContext.HttpContext.Request.UserHostAddress,
             Challenge = captchaChallengeValue,
             Response = captchaResponseValue
         }.Validate();
         filterContext.ActionParameters["captchaValid"] = recaptchaResponse.IsValid;
         base.OnActionExecuting(filterContext);
     }
 }
コード例 #11
0
   public override void OnActionExecuting(ActionExecutingContext filterContext)  
       {  
           var captchaChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];  
           var captchaResponseValue = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];  
           var captchaValidtor = new Recaptcha.RecaptchaValidator  
                                     {
                                         PrivateKey = "6Lcx9xQTAAAAANDEAaVhJO686nDs9WZfqI-fgoxp",  
                                         RemoteIP = filterContext.HttpContext.Request.UserHostAddress,  
                                         Challenge = captchaChallengeValue,  
                                         Response = captchaResponseValue  
                                     };  
 
           var recaptchaResponse = captchaValidtor.Validate();  
 
       // this will push the result value into a parameter in our Action  
           filterContext.ActionParameters["captchaValid"] = recaptchaResponse.IsValid;
       if (!recaptchaResponse.IsValid)
       {
           filterContext.Controller.ViewData.ModelState.AddModelError("Captcha", "Капча введена неверно");
       }
           
           base.OnActionExecuting(filterContext);  
       }
コード例 #12
0
		public override void OnActionExecuting(ActionExecutingContext filterContext)
		{
			Roadkill.Core.Mvc.Controllers.ControllerBase controller = filterContext.Controller as Roadkill.Core.Mvc.Controllers.ControllerBase;
			if (controller != null)
			{
				SiteSettings siteSettings = controller.SettingsService.GetSiteSettings();
				if (siteSettings.IsRecaptchaEnabled)
				{
					string challengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_KEY];
					string responseValue = filterContext.HttpContext.Request.Form[RESPONSE_KEY];

					RecaptchaValidator validator = new RecaptchaValidator();
					validator.PrivateKey = siteSettings.RecaptchaPrivateKey;
					validator.RemoteIP = filterContext.HttpContext.Request.UserHostAddress;
					validator.Challenge = challengeValue;
					validator.Response = responseValue;

					RecaptchaResponse validationResponse = validator.Validate();
					filterContext.ActionParameters["isCaptchaValid"] = validationResponse.IsValid;
				}
			}

			base.OnActionExecuting(filterContext);
		}
コード例 #13
0
        /// <summary>
        /// Perform validation of reCAPTCHA.
        /// </summary>
        public void Validate()
        {
            if (Page.IsPostBack && Visible && Enabled && !this.skipRecaptcha)
            {
                if (this.recaptchaResponse == null)
                {
                    if (Visible && Enabled)
                    {
                        RecaptchaValidator validator = new RecaptchaValidator();
                        validator.PrivateKey = this.PrivateKey;
                        validator.RemoteIP = Page.Request.UserHostAddress;
                        validator.Challenge = Context.Request.Form[RECAPTCHA_CHALLENGE_FIELD];
                        validator.Response = Context.Request.Form[RECAPTCHA_RESPONSE_FIELD];
                        validator.Proxy = this.proxy;

                        if (validator.Challenge == null)
                        {
                            this.recaptchaResponse = RecaptchaResponse.InvalidChallenge;
                        }
                        else if (validator.Response == null)
                        {
                            this.recaptchaResponse = RecaptchaResponse.InvalidResponse;
                        }
                        else
                        {
                            this.recaptchaResponse = validator.Validate();
                        }
                    }
                }
            }
            else
            {
                this.recaptchaResponse = RecaptchaResponse.Valid;
            }
        }
コード例 #14
0
        public void Validate()
        {
            if (skipRecaptcha)
            {
                recaptchaResponse = RecaptchaResponse.Valid;
            }
            else
            {
                RecaptchaValidator validator = new RecaptchaValidator();
                validator.PrivateKey = privateKey;
                validator.RemoteIP = Page.Request.UserHostAddress;
                if (String.IsNullOrEmpty(RecaptchaChallengeValue) && String.IsNullOrEmpty(RecaptchaResponseValue))
                {
                    validator.Challenge = Context.Request.Form[RECAPTCHA_CHALLENGE_FIELD];
                    validator.Response = Context.Request.Form[RECAPTCHA_RESPONSE_FIELD];
                }
                else
                {
                    validator.Challenge = RecaptchaChallengeValue;
                    validator.Response = RecaptchaResponseValue;
                }

                recaptchaResponse = validator.Validate();
            }
        }
コード例 #15
0
 public JsonResult ReplyToAPost(bool captchaValid, ReplyPost replyPostModel)
 {
     try
     {
         RecaptchaValidator va = new RecaptchaValidator();
         va.Validate();
         if (captchaValid)
         {
             return Json(new { success = "other" });
         }
         else
         {
             var mailMessage = replyPostModel.GetReplyToAPostMessage();
             var email = new Email(mailMessage);
             email.Send();
             return Json(new { success = "true" });
         }
     }
     catch (Exception)
     {
         return Json(new { success = "false" });
     }
 }
コード例 #16
0
        /// <summary>
        /// The validate.
        /// </summary>
        public void Validate()
        {
            if (this.skipRecaptcha)
            {
                this.recaptchaResponse = RecaptchaResponse.Valid;
            }
            else
            {
                var validator = new RecaptchaValidator
                    {
                       PrivateKey = this.privateKey, RemoteIP = Utils.GetClientIP()
                    };
                if (String.IsNullOrEmpty(this.RecaptchaChallengeValue) &&
                    String.IsNullOrEmpty(this.RecaptchaResponseValue))
                {
                    validator.Challenge = this.Context.Request.Form[RecaptchaChallengeField];
                    validator.Response = this.Context.Request.Form[RecaptchaResponseField];
                }
                else
                {
                    validator.Challenge = this.RecaptchaChallengeValue;
                    validator.Response = this.RecaptchaResponseValue;
                }

                this.recaptchaResponse = validator.Validate();
            }
        }
コード例 #17
0
ファイル: RecaptchaControl.cs プロジェクト: kohku/codefactory
        public void Validate()
        {
            if (skipRecaptcha) {
                recaptchaResponse = RecaptchaResponse.Valid;
                isValid = true;
            } else {
                RecaptchaValidator validator = new RecaptchaValidator();
                validator.PrivateKey = PrivateKey;
                validator.RemoteIP = Page.Request.UserHostAddress;
                validator.Challenge = Context.Request.Form[RECAPTCHA_CHALLENGE_FIELD];
                validator.Response = Context.Request.Form[RECAPTCHA_RESPONSE_FIELD];

                recaptchaResponse = validator.Validate();
                isValid = recaptchaResponse.IsValid;
            }
        }
コード例 #18
0
 public ReCaptchaValidator(IConfigurationSource configSource)
 {
     _configSource = configSource;
     _recaptchaValidator = new RecaptchaValidator();
 }