public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var privateKey = ConfigurationManager.AppSettings["recaptcha.privateKey"];

            if (String.IsNullOrEmpty(privateKey))
                throw new ConfigurationErrorsException("The key 'recaptcha.privateKey' must be defined in your config file");

            var captchaValidator = new Recaptcha.RecaptchaValidator
            {
                PrivateKey = privateKey,
                RemoteIP = filterContext.HttpContext.Request.UserHostAddress,
                Challenge = filterContext.HttpContext.Request.Form[ChallengeFieldKey] ?? String.Empty,
                Response = filterContext.HttpContext.Request.Form[ResponseFieldKey] ?? String.Empty
            };

            var captchaResponse = captchaValidator.Validate();

            // Push the result value into a parameter in our Action
            filterContext.ActionParameters[_resultKey] = captchaResponse.IsValid;

            // Set the Model State error
            if (!captchaResponse.IsValid && _setModelStateError)
            {
                filterContext.Controller.ViewData.ModelState.AddModelError(_resultKey, _errorMessage);
            }

            base.OnActionExecuting(filterContext);
        }
        public ActionResult Captcha(FormCollection form)
        {
            var challenge = form.Get<string>("recaptcha_challenge_field", "");

            var validator = new Recaptcha.RecaptchaValidator
            {
                PrivateKey = AppSettings.RecaptchaPrivateKey,
                RemoteIP = GetRemoteIP(),
                Challenge = challenge,
                Response = form.Get<string>("recaptcha_response_field", "")
            };

            Recaptcha.RecaptchaResponse response;

            try
            {
                response = validator.Validate();
            }
            catch (WebException)
            {
                // recaptcha is down - if the challenge had some length (it's usually a massive hash), allow the action - spam will be destroyed by the community
                response = challenge.Length >= 30 ? Recaptcha.RecaptchaResponse.Valid : Recaptcha.RecaptchaResponse.RecaptchaNotReachable;
            }

            if (response == Recaptcha.RecaptchaResponse.Valid)
            {
                Current.SetCachedObjectSliding(CaptchaKey(GetRemoteIP()), true, 60 * 15);
                return Json(new { success = true });
            }

            return  Json(new { success = false });;
        }
        public ActionResult Captcha(FormCollection form)
        {
            var challenge = form.Get("recaptcha_challenge_field", "");

            var validator = new Recaptcha.RecaptchaValidator
            {
                PrivateKey = AppSettings.RecaptchaPrivateKey,
                RemoteIP   = Current.RemoteIP,
                Challenge  = challenge,
                Response   = form.Get("recaptcha_response_field", "")
            };

            Recaptcha.RecaptchaResponse response;

            try
            {
                response = validator.Validate();
            }
            catch (WebException)
            {
                // recaptcha is down - if the challenge had some length (it's usually a massive hash), allow the action - spam will be destroyed by the community
                response = challenge.Length >= 30 ? Recaptcha.RecaptchaResponse.Valid : Recaptcha.RecaptchaResponse.RecaptchaNotReachable;
            }

            if (response == Recaptcha.RecaptchaResponse.Valid)
            {
                Current.SetCachedObjectSliding(CaptchaKey(Current.RemoteIP), true, 60 * 15);
                return(Json(new { success = true }));
            }

            return(Json(new { success = false }));;
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            bool valid = false;
            var captchaChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
            var captchaResponseValue = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
            if (!string.IsNullOrEmpty(captchaChallengeValue) && !string.IsNullOrEmpty(captchaResponseValue))
            {

                    //validate captcha
                    var captchaValidtor = new Recaptcha.RecaptchaValidator
                    {
                        //PrivateKey = "6LdIPB4TAAAAAJ3UVZFyyY9mI3DBELNFjw-ODTp7",//captchaSettings.ReCaptchaPrivateKey,
                        PrivateKey = "6LekyyATAAAAAABSNFkB4B0gp0FE9d4JA2MtyQU7",//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["captchaValid"] = valid;

            base.OnActionExecuting(filterContext);
        }
        public ReturnObject CheckCaptcha(UserRequest Object)
        {
            try
            {
                OperationContext context = OperationContext.Current;
                MessageProperties messageProperties = context.IncomingMessageProperties;
                RemoteEndpointMessageProperty endpointProperty = messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

                Recaptcha.RecaptchaValidator captchaValidtor = new Recaptcha.RecaptchaValidator
                {
                    PrivateKey = System.Web.Configuration.WebConfigurationManager.AppSettings["PRIVATE_KEY"].ToString(),
                    RemoteIP = endpointProperty.Address,
                    Challenge = Object.challenge,
                    Response = Object.response
                };

                Recaptcha.RecaptchaResponse recaptchaResponse = captchaValidtor.Validate();
                ReturnObject rObj = new ReturnObject(recaptchaResponse.IsValid, recaptchaResponse.ErrorMessage, "");
                return rObj;
            }
            catch (Exception ex) {
                ReturnObject rObj = new ReturnObject(false, ex.Message, "");
                return rObj;
            }
        }
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                if (SkipRecaptcha)
                {
                    filterContext.ActionParameters["captchaValid"] = true;
                }
                else
                {
                    RecaptchaValidator validator = new Recaptcha.RecaptchaValidator();
                    validator.PrivateKey = RecaptchaControlMvc.PrivateKey;
                    validator.RemoteIP   = filterContext.HttpContext.Request.UserHostAddress;
                    validator.Challenge  = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
                    validator.Response   = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
                    validator.Proxy      = proxy;

                    if (string.IsNullOrEmpty(validator.Challenge))
                    {
                        this.recaptchaResponse = RecaptchaResponse.InvalidChallenge;
                    }
                    else if (string.IsNullOrEmpty(validator.Response))
                    {
                        this.recaptchaResponse = RecaptchaResponse.InvalidResponse;
                    }
                    else
                    {
                        this.recaptchaResponse = validator.Validate();
                    }

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

                base.OnActionExecuting(filterContext);
            }
Beispiel #7
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            bool valid = false;
            var  captchaChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
            var  captchaResponseValue  = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];

            if (!string.IsNullOrEmpty(captchaChallengeValue) && !string.IsNullOrEmpty(captchaResponseValue))
            {
                var captchaSettings = EngineContext.Current.Resolve <CaptchaSettings>();
                if (captchaSettings.Enabled)
                {
                    //validate captcha
                    var captchaValidtor = new Recaptcha.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["captchaValid"] = valid;

            base.OnActionExecuting(filterContext);
        }
Beispiel #8
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var privateKey            = ConfigurationManager.AppSettings["RecaptchaPrivate"];
            var captchaChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
            var captchaResponseValue  = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
            var captchaValidtor       = new Recaptcha.RecaptchaValidator
            {
                PrivateKey = privateKey,
                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 is Controller)
            {
                var controller = filterContext.Controller as Controller;
                controller.ModelState.AddModelError("CaptchaValid", "Captcha wasn't recognised please try again.");
            }

            base.OnActionExecuting(filterContext);
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            bool valid = false;
            var  captchaChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
            var  captchaResponseValue  = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];

            if (!string.IsNullOrEmpty(captchaChallengeValue) && !string.IsNullOrEmpty(captchaResponseValue))
            {
                //validate captcha
                var captchaValidtor = new Recaptcha.RecaptchaValidator
                {
                    //PrivateKey = "6LdIPB4TAAAAAJ3UVZFyyY9mI3DBELNFjw-ODTp7",//captchaSettings.ReCaptchaPrivateKey,
                    PrivateKey = "6LekyyATAAAAAABSNFkB4B0gp0FE9d4JA2MtyQU7",    //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["captchaValid"] = valid;

            base.OnActionExecuting(filterContext);
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var privateKey = ConfigurationManager.AppSettings["RecaptchaPrivate"];
            var captchaChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
            var captchaResponseValue = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
            var captchaValidtor = new Recaptcha.RecaptchaValidator
                                      {
                                          PrivateKey = privateKey,
                                          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 is Controller)
            {
                var controller = filterContext.Controller as Controller;
                controller.ModelState.AddModelError("CaptchaValid", "Captcha wasn't recognised please try again.");
            }

            base.OnActionExecuting(filterContext);
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var privateKey = ConfigurationManager.AppSettings["recaptcha.privateKey"];

            if (String.IsNullOrEmpty(privateKey))
            {
                throw new ConfigurationErrorsException("The key 'recaptcha.privateKey' must be defined in your config file");
            }

            var captchaValidator = new Recaptcha.RecaptchaValidator
            {
                PrivateKey = privateKey,
                RemoteIP   = filterContext.HttpContext.Request.UserHostAddress,
                Challenge  = filterContext.HttpContext.Request.Form[ChallengeFieldKey] ?? String.Empty,
                Response   = filterContext.HttpContext.Request.Form[ResponseFieldKey] ?? String.Empty
            };

            var captchaResponse = captchaValidator.Validate();

            // Push the result value into a parameter in our Action
            filterContext.ActionParameters[_resultKey] = captchaResponse.IsValid;

            // Set the Model State error
            if (!captchaResponse.IsValid && _setModelStateError)
            {
                filterContext.Controller.ViewData.ModelState.AddModelError(_resultKey, _errorMessage);
            }

            base.OnActionExecuting(filterContext);
        }
Beispiel #12
0
        public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            var jsonStr = actionContext.Request.Content.ReadAsStringAsync().Result;
            var msgObj = Json.Decode(jsonStr);

            bindingContext.Model = new Msg
            {
                UserName = msgObj.UserName,
                Email = msgObj.Email,
                HomePage = msgObj.HomePage,
                Text = msgObj.Text,
                Date = DateTime.Now
            };

            var captchaValidtor = new Recaptcha.RecaptchaValidator
            {
                PrivateKey = ConfigurationManager.AppSettings["ReCaptchaPrivateKey"],
                RemoteIP = ((System.Web.HttpContextWrapper)actionContext.Request.Properties["MS_HttpContext"]).Request.UserHostAddress,
                Challenge = msgObj.recaptcha_challenge_field,
                Response = msgObj.recaptcha_response_field
            };

            var recaptchaResponse = captchaValidtor.Validate();
            if (!recaptchaResponse.IsValid)
            {
                actionContext.ModelState.AddModelError("recaptcha_response_field", "Символы не соответствуют картинке.");
            }
            return true;
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            bool valid = false;
            var captchaChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
            var captchaResponseValue = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
            if (!string.IsNullOrEmpty(captchaChallengeValue) && !string.IsNullOrEmpty(captchaResponseValue))
            {
                var captchaSettings = EngineContext.Current.Resolve<CaptchaSettings>();
                if (captchaSettings.Enabled)
                {
                    //validate captcha
                    var captchaValidtor = new Recaptcha.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["captchaValid"] = valid;

            base.OnActionExecuting(filterContext);
        }
Beispiel #14
0
        /// <summary>
        /// validate a captcha challenge
        /// </summary>
        /// <param name="captchaChallengeValue"></param>
        /// <param name="captchaResponseValue"></param>
        /// <returns></returns>
        public static bool Validate(string privatekey, string captchaChallengeValue, string captchaResponseValue)
        {
            var captchaValidtor = new Recaptcha.RecaptchaValidator
             {
            PrivateKey = privatekey,
            RemoteIP = HttpContext.Current.Request.UserHostAddress,
            Challenge = captchaChallengeValue,
            Response = captchaResponseValue
             };

             var recaptchaResponse = captchaValidtor.Validate();
             return recaptchaResponse.IsValid;
        }
        public bool myValidator(string captchaChallengeValue, string captchaResponseValue)
        {
            var captchaValidtor = new Recaptcha.RecaptchaValidator
            {
                PrivateKey = ConfigurationManager.AppSettings["ReCaptchaPrivateKey"],
                RemoteIP = HttpContext.Current.Request.UserHostAddress, // Request.UserHostAddress,
                Challenge = captchaChallengeValue,
                Response = captchaResponseValue
            };

            var recaptchaResponse = captchaValidtor.Validate();

            return recaptchaResponse.IsValid;
        }
        public bool IsCaptchaValid(string captchaChallengeValue, string captchaResponseValue, string userHostAddress)
        {
            _captchaSettings = _orchardServices.WorkContext.CurrentSite.As <CaptchaSettingsPart>();
            var captchaValidtor = new Recaptcha.RecaptchaValidator {
                PrivateKey = _captchaSettings.PrivateKey,
                RemoteIP   = userHostAddress,
                Challenge  = captchaChallengeValue,
                Response   = captchaResponseValue
            };

            var recaptchaResponse = captchaValidtor.Validate();

            // this will push the result value into a parameter in our Action
            return(recaptchaResponse.IsValid);
        }
Beispiel #17
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var captchaChallengeValue = filterContext.HttpContext.Request.Form[ChallengeFieldKey];
            var captchaResponseValue  = filterContext.HttpContext.Request.Form[ResponseFieldKey];
            var captchaValidtor       = new Recaptcha.RecaptchaValidator {
                PrivateKey = ConfigurationManager.AppSettings["ReCaptchaPrivateKey"],
                RemoteIP   = filterContext.HttpContext.Request.UserHostAddress,
                Challenge  = captchaChallengeValue,
                Response   = captchaResponseValue
            };

            var recaptchaResponse = captchaValidtor.Validate();

            filterContext.ActionParameters["captchaValid"] = recaptchaResponse.IsValid;
            base.OnActionExecuting(filterContext);
        }
        public bool IsCaptchaValid(FormCollection form, string userHostAddress)
        {
            var captchaChallengeValue = form[ChallengeFieldKey];
            var captchaResponseValue = form[ResponseFieldKey];
            var captchaValidtor = new Recaptcha.RecaptchaValidator
            {
                PrivateKey = CaptchaPart.PrivateKey,
                RemoteIP = userHostAddress,
                Challenge = captchaChallengeValue,
                Response = captchaResponseValue
            };

            var recaptchaResponse = captchaValidtor.Validate();

            // this will push the result value into a parameter in our Action   
            return recaptchaResponse.IsValid;
        }
        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 captchaValidator = new Recaptcha.RecaptchaValidator
                                        {
                                            PrivateKey = ConfigurationManager.AppSettings["reCaptcha-PrivateKey"],
                                            RemoteIP = filterContext.HttpContext.Request.UserHostAddress,
                                            Challenge = captchaChallengeValue,
                                            Response = captchaResponseValue
                                        };

            var recaptchaResponse = captchaValidator.Validate();

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

            base.OnActionExecuting(filterContext);
        }
        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 = ConfigurationManager.AppSettings["RecaptchaPrivateKey"],
                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);
        }
Beispiel #21
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 = "6LeAousSAAAAADqiHv12jipV3AsBUrJ9DJuUaQId",
                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);
        }
Beispiel #22
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var captChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
            var captResponseValue  = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];

            var catpchaValidator = new Recaptcha.RecaptchaValidator
            {
                PrivateKey = MvcApplication.CaptchaPrivateKey,
                RemoteIP   = filterContext.HttpContext.Request.UserHostAddress,
                Challenge  = captChallengeValue,
                Response   = captResponseValue
            };

            var recaptchaResponse = catpchaValidator.Validate();

            filterContext.ActionParameters["validCaptcha"] = recaptchaResponse.IsValid;

            base.OnActionExecuting(filterContext);
        }
        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 = "6Lc-KwYAAAAAANt8fE-8H3KtrFClNIz4f5FSqG4p",
                                          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);
        }
        /// <summary>
        /// Called before the action method is invoked
        /// </summary>
        /// <param name="filterContext">Information about the current request and action</param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var captchaChallengeValue = filterContext.HttpContext.Request.Form[ChallengeFieldKey];
            var captchaResponseValue = filterContext.HttpContext.Request.Form[ResponseFieldKey];
            var captchaValidtor = new Recaptcha.RecaptchaValidator
                                      {
                                          PrivateKey = ConfigurationManager.AppSettings["ReCaptchaPrivateKey"],
                                          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("recaptcha", "incorrect user input");

            base.OnActionExecuting(filterContext);
        }
        /// <summary>
        /// Called before the action method is invoked
        /// </summary>
        /// <param name="filterContext">Information about the current request and action</param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var captchaChallengeValue = filterContext.HttpContext.Request.Form[ChallengeFieldKey];
            var captchaResponseValue  = filterContext.HttpContext.Request.Form[ResponseFieldKey];
            var captchaValidtor       = new Recaptcha.RecaptchaValidator
            {
                PrivateKey = ConfigurationManager.AppSettings["ReCaptchaPrivateKey"],
                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);

            // Add string to Trace for testing
            //filterContext.HttpContext.Trace.Write("Log: OnActionExecuting", String.Format("Calling {0}", filterContext.ActionDescriptor.ActionName));
        }
 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 = "key",
         RemoteIP = filterContext.HttpContext.Request.UserHostAddress,
         Challenge = captchaChallengeValue,
         Response = captchaResponseValue
     };
     var recaptchaResponse = captchaValidtor.Validate();
     if (!recaptchaResponse.IsValid)
     {
         filterContext.Controller
             .ViewData.ModelState
             .AddModelError(
                 CAPTCHA_MODEL_KEY,
                 "Entered text is invalid");
     }
     base.OnActionExecuting(filterContext);
 }
Beispiel #27
0
        /// <summary>
        /// Verify that the given form contains a solution to a captcha.
        ///
        /// If not, message will contain something suitable for display to a user.
        /// </summary>
        public static bool Verify(NameValueCollection form, out string message)
        {
            var challenge = form["recaptcha_challenge_field"];
            var response  = form["recaptcha_response_field"];

            if (!challenge.HasValue() || !response.HasValue())
            {
                message = "Captcha failed";

                return(false);
            }

            var captcha = new Recaptcha.RecaptchaValidator();

            captcha.RemoteIP   = Current.RemoteIP;
            captcha.Challenge  = challenge;
            captcha.Response   = response;
            captcha.PrivateKey = WebConfigurationManager.AppSettings["ReCaptchaPrivateKey"];

            try
            {
                var res = captcha.Validate();
                if (res != Recaptcha.RecaptchaResponse.Valid)
                {
                    message = "Captcha failed - " + res.ErrorMessage;
                    return(false);
                }
            }
            catch (WebException)
            {
                message = "There was a problem communicating with ReCaptcha, please try again";

                return(false);
            }

            message = "";

            return(true);
        }
        /// <summary>
        /// Called before the action method is invoked
        /// </summary>
        /// <param name="filterContext">Information about the current request and action</param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var captchaChallengeValue = filterContext.HttpContext.Request.Form[ChallengeFieldKey];
            var captchaResponseValue = filterContext.HttpContext.Request.Form[ResponseFieldKey];
            var captchaValidtor = new Recaptcha.RecaptchaValidator
            {
                PrivateKey = ConfigurationManager.AppSettings["ReCaptchaPrivateKey"],
                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);

            // Add string to Trace for testing
            //filterContext.HttpContext.Trace.Write("Log: OnActionExecuting", String.Format("Calling {0}", filterContext.ActionDescriptor.ActionName));
        }
Beispiel #29
0
        /// <summary>
        /// Verify that the given form contains a solution to a captcha.
        /// 
        /// If not, message will contain something suitable for display to a user.
        /// </summary>
        public static bool Verify(NameValueCollection form, out string message)
        {
            var challenge = form["recaptcha_challenge_field"];
            var response = form["recaptcha_response_field"];

            if (!challenge.HasValue() || !response.HasValue())
            {
                message = "Captcha failed";

                return false;
            }

            var captcha = new Recaptcha.RecaptchaValidator();
            captcha.RemoteIP = Current.RemoteIP;
            captcha.Challenge = challenge;
            captcha.Response = response;
            captcha.PrivateKey = WebConfigurationManager.AppSettings["ReCaptchaPrivateKey"];

            try
            {
                var res = captcha.Validate();
                if (res != Recaptcha.RecaptchaResponse.Valid)
                {
                    message = "Captcha failed - " + res.ErrorMessage;
                    return false;
                }
            }
            catch (WebException)
            {
                message = "There was a problem communicating with ReCaptcha, please try again";

                return false;
            }

            message = "";

            return true;
        }
Beispiel #30
0
        protected void LoginUser_OnAuthenticate(object sender, AuthenticateEventArgs e)
        {
            // always set to false
            e.Authenticated = false;

            try {
                var validator = new Recaptcha.RecaptchaValidator
                {
                    PrivateKey = RECAPTCHA_SECRET_KEY,
                    RemoteIP   = Utils.GetClientIP(),
                    Response   = Context.Request.Form["g-recaptcha-response"]
                };

                var result = validator.Validate();
                if (result.IsValid)
                {
                    Security.AuthenticateUser(LoginUser.UserName, LoginUser.Password, LoginUser.RememberMeSet);
                }
            } catch (ThreadAbortException) {
            } catch (ArgumentNullException) {
            } catch (Exception ex) {
                Utils.Log("Login User Authenticate", ex);
            }
        }
        public ActionResult QuieroSerCliente(string nombre, string email, string telefono, string calle,
            string exterior, string interior, string entrecalles, string colonia, string municipio,
            string entidad, string asunto, string mensaje, string operation, string cpostal, string lada, string horario, string privacidad)
        {
            asunto = "Contratación de servicios";
            var regex =
                new Regex(
                    @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");

            if (Request.QueryString.Count != 0 && Request.QueryString["type"] == "contratacion") {
                //?type=contratacion&combo=Max Conéctate 3&tv=&Uacute;nico HBO&cel=Libre&total=856
                ViewData["Paquete"] = "<p>Seleccionaste: </p>\n	<ul>\n";
                if (Request.QueryString["combo"] != null)
                    ViewData["Paquete"] += "<li><b>Combo:</b>&nbsp;" + Request.QueryString["combo"] + "</li>\n";
                if (Request.QueryString["tv"] != null)
                    ViewData["Paquete"] += "<li><b>TV:</b>&nbsp;" + Request.QueryString["tv"] + "</li>\n";
                if (Request.QueryString["cel"] != null)
                    ViewData["Paquete"] += "<li><b>Celular:</b>&nbsp;" + Request.QueryString["cel"] + "</li>\n";
                if (Request.QueryString["total"] != null)
                    ViewData["Paquete"] += @"</ul><div class=""resumen"">
            <strong class=""precio"">$" + Request.QueryString["total"] + @"</strong>
            <p>Al mes por todos tus servicios</p>
            </div>";
            }
            if (string.IsNullOrEmpty(operation)) return View();

            ViewData["QuieroNombre"] = nombre;
            ViewData["QuieroEmail"] = email;
            ViewData["QuieroTelefono"] = telefono;
            ViewData["QuieroCalle"] = calle;
            ViewData["QuieroExterior"] = exterior;
            ViewData["QuieroInterior"] = interior;
            ViewData["QuieroEntrecalles"] = entrecalles;
            ViewData["QuieroColonia"] = colonia;
            ViewData["QuieroCP"] = cpostal;
            ViewData["QuieroMunicipio"] = municipio;
            ViewData["QuieroMensaje"] = mensaje;
            ViewData["QuieroLada"] = lada;
            ViewData["QuieroHorario"] = horario;
            ViewData["QuieroPrivacidad"] = privacidad;
            var msg = "";
            if (string.IsNullOrEmpty(((((System.Web.Mvc.Controller)(this)).Request).Form)["recaptcha_response_field"])) {
                ViewData["QuieroException"] = "<img src=\"/img/error.png\"/> Por favor completa el Captcha.";
            } else {
                var response = new Recaptcha.RecaptchaValidator {
                    Challenge = ((((System.Web.Mvc.Controller)(this)).Request).Form)["recaptcha_challenge_field"],
                    Response = ((((System.Web.Mvc.Controller)(this)).Request).Form)["recaptcha_response_field"],
                    PrivateKey = "6LfumgcTAAAAAG4_s8P4MPcePXs8Oaoi_QItaIT6",
                    RemoteIP = GetUserIPAddress()
                }.Validate();
                if (!response.IsValid)
                    ViewData["QuieroException"] = "<img src=\"/img/error.png\"/> Hubo un error al validar el Captcha.";
            }
            /*var request =
                WebRequest.Create(
                    string.Format(
                        "https://www.google.com/recaptcha/api/siteverify?secret=6LfumgcTAAAAAG4_s8P4MPcePXs8Oaoi_QItaIT6&response={0}",
                        Request.Form["g-recaptcha-response"]));
            request.Method = "POST";
            request.ContentLength = 0;
            using (var response = request.GetResponse()) {
                Console.WriteLine(((HttpWebResponse) response).StatusDescription);
                using (var responseDataStream = response.GetResponseStream()) {
                    if (responseDataStream == null)
                        ViewData["QuieroException"] = "<img src=\"/img/error.png\"/> Por favor completa el Captcha.";
                    else {
                        using (var reader = new StreamReader(responseDataStream)) {
                            var responseFromServer = reader.ReadToEnd();
                            if (!responseFromServer.Contains("true")) {
                                ViewData["QuieroException"] =
                                    "<img src=\"/img/error.png\"/> Por favor completa el Captcha.";
                            }
                        }
                    }
                }
            }*/
            if (string.IsNullOrEmpty(nombre) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(telefono) ||
                (string.IsNullOrEmpty(asunto) || asunto == "Selecciona una opción") || string.IsNullOrEmpty(mensaje))
                ViewData["QuieroException"] = "<img src=\"/img/error.png\"/> Por favor llena todos los campos.";
            else {
                if (!regex.IsMatch(email)) {
                    ViewData["QuieroException"] =
                        "<img src=\"/img/error.png\"/> La dirección de correo electrónico no es v&aacute;lida.";
                }
                ViewData[asunto] = "selected";
            }
            if (asunto != "Contratación de servicios") {
                if (ViewData.ContainsKey("QuieroException")) return View();
                if (Request.QueryString.Count == 0) {
                    ViewData["Paquete"] = "";
                        //qs = Request.QueryString.AllKeys.Aggregate(QueryStringInfo, (current, data) => current + string.Format("<p><b>{0}:</b>&nbsp;{1}</p>", data, Request.QueryString[data]));
                }
                    msg = string.Format(Template, nombre, email, telefono, asunto, mensaje, "", ViewData["Paquete"], "");
                    ViewData["QuieroSuccess"] = SendEmailQuieroSer(msg, "Contacto Atención a clientes Maxcom", email);
                if ((string) ViewData["QuieroSuccess"] == "OK")
                    return RedirectToAction("Gracias");
                return View();
            }
            if (string.IsNullOrEmpty(calle) || string.IsNullOrEmpty(exterior) || string.IsNullOrEmpty(colonia) ||
                string.IsNullOrEmpty(municipio) || (string.IsNullOrEmpty(entidad) || entidad == "Selecciona tu Entidad") ||
                string.IsNullOrEmpty(cpostal))
                ViewData["QuieroException"] = "<img src=\"/img/error.png\"/>Por favor llena todos los campos.";
            ViewData["QuieroCall"] = " onload='call();' ";
            ViewData[entidad] = "selected";
            if (privacidad == null) {
                ViewData["QuieroException"] =
                        "<img src=\"/img/error.png\"/> Por favor, lee y acepta nuestro aviso de privacidad.";
            }
            if (ViewData.ContainsKey("QuieroException")) return View();
            var xtra = string.Format(AdditionalInfo, calle, exterior, interior, entrecalles, colonia, municipio, entidad, cpostal);
            if (Request.QueryString.Count == 0) {
                ViewData["Paquete"] = "";
                    //qs = Request.QueryString.AllKeys.Aggregate(QueryStringInfo, (current, data) => current + string.Format("<p><b>{0}:</b>&nbsp;{1}</p>", data, Request.QueryString[data]));
            }
            msg = string.Format(Template, nombre, email, lada + " - " + telefono, asunto, mensaje, xtra, ViewData["Paquete"], "", horario);
            ViewData["QuieroSuccess"] = SendEmailQuieroSer(msg, "Contacto Atención a clientes Maxcom", email);
            if ((string) ViewData["QuieroSuccess"] == "OK")
                return RedirectToAction("Gracias");
            return View();
        }
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                if (SkipRecaptcha)
                {
                    filterContext.ActionParameters["captchaValid"] = true;
                }
                else
                {
                    RecaptchaValidator validator = new Recaptcha.RecaptchaValidator();
                    validator.PrivateKey = RecaptchaControlMvc.PrivateKey;
                    validator.RemoteIP = filterContext.HttpContext.Request.UserHostAddress;
                    validator.Challenge = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
                    validator.Response = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
                    validator.Proxy = proxy;

                    if (string.IsNullOrEmpty(validator.Challenge))
                    {
                        this.recaptchaResponse = RecaptchaResponse.InvalidChallenge;
                    }
                    else if (string.IsNullOrEmpty(validator.Response))
                    {
                        this.recaptchaResponse = RecaptchaResponse.InvalidResponse;
                    }
                    else
                    {
                        this.recaptchaResponse = validator.Validate();
                    }

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

                base.OnActionExecuting(filterContext);
            }
Beispiel #33
0
        public bool captchaValidate()
        {
            string ChallengeFieldKey = "recaptcha_challenge_field";
            string ResponseFieldKey = "recaptcha_response_field";

            var captchaChallengeValue = HttpContext.Request.Form[ChallengeFieldKey];
            var captchaResponseValue = HttpContext.Request.Form[ResponseFieldKey];
            var captchaValidtor = new Recaptcha.RecaptchaValidator
                                      {
                                          PrivateKey = ConfigurationManager.AppSettings["ReCaptchaPrivateKey"],
                                          RemoteIP = HttpContext.Request.UserHostAddress,
                                          Challenge = captchaChallengeValue,
                                          Response = captchaResponseValue
                                      };

            var recaptchaResponse = captchaValidtor.Validate();

            return recaptchaResponse.IsValid;
        }
 public ActionResult YaSoyCliente(string nombre, string contrato, string email, string telefono,
     string asunto, string mensaje, string operation, string lada, string horario, string privacidad)
 {
     var regex =
         new Regex(
             @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
     if (string.IsNullOrEmpty(operation)) return View();
     ViewData["YaSoyNombre"] = nombre;
     ViewData["YaSoyContrato"] = contrato;
     ViewData["YaSoyEmail"] = email;
     ViewData["YaSoyTelefono"] = telefono;
     ViewData["YaSoyMensaje"] = mensaje;
     ViewData["YaSoyLada"] = lada;
     ViewData["YaSoyHorario"] = horario;
     ViewData["YaSoyPrivacidad"] = privacidad;
     var qs = "";
     if (string.IsNullOrEmpty(((((System.Web.Mvc.Controller)(this)).Request).Form)["recaptcha_response_field"])) {
         ViewData["YaSoyException"] = "<img src=\"/img/error.png\"/> Por favor completa el Captcha.";
     } else {
         var response = new Recaptcha.RecaptchaValidator {
             Challenge = ((((System.Web.Mvc.Controller)(this)).Request).Form)["recaptcha_challenge_field"],
             Response = ((((System.Web.Mvc.Controller)(this)).Request).Form)["recaptcha_response_field"],
             PrivateKey = "6LfumgcTAAAAAG4_s8P4MPcePXs8Oaoi_QItaIT6",
             RemoteIP = GetUserIPAddress()
         }.Validate();
         if (!response.IsValid)
             ViewData["YaSoyException"] = "<img src=\"/img/error.png\"/> Hubo un error al validar el Captcha.";
     }
     if (string.IsNullOrEmpty(nombre) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(contrato) ||
         string.IsNullOrEmpty(telefono) || (string.IsNullOrEmpty(asunto) || asunto == "Selecciona una opción") ||
         string.IsNullOrEmpty(mensaje))
         ViewData["YaSoyException"] = "<img src=\"/img/error.png\"/> Por favor llena todos los campos.";
     else {
         if (!regex.IsMatch(email)) {
             ViewData["YaSoyException"] =
                 "<img src=\"/img/error.png\"/> La dirección de correo electrónico no es v&aacute;lida.";
         }
         ViewData[asunto] = "selected";
     }
     if (privacidad == null) {
         ViewData["YaSoyException"] =
                 "<img src=\"/img/error.png\"/> Por favor, lee y acepta nuestro aviso de privacidad.";
     }
     if (ViewData.ContainsKey("YaSoyException")) return View();
     if (Request.QueryString.Count != 0) {
         qs = Request.QueryString.AllKeys.Aggregate(QueryStringInfo,
             (current, data) =>
                 current + string.Format("<p><b>{0}:</b>&nbsp;{1}</p>", data, Request.QueryString[data]));
     }
     var msg = string.Format(Template, nombre, email, lada + " - " + telefono, asunto, mensaje, "", qs,
         string.Format("<p><b>Número de cuenta Maxcom:</b>&nbsp;{0}</p>", contrato), horario);
     ViewData["YaSoySuccess"] = SendEmailYaSoy(msg, "Contacto Atención a clientes Maxcom", email);
     if ((string) ViewData["YaSoySuccess"] == "OK")
         return RedirectToAction("Gracias");
     return View();
 }
        public ActionResult ContactoComercial(string nombre, string puesto, string empresa, string email, string empleados,
            string telefono, string direccion, string asunto, string cual, string mensaje, string operation, string privacidad)
        {
            var regex = new Regex(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
            if (string.IsNullOrEmpty(operation)) return View();
            ViewData["Nombre"] = nombre;
            ViewData["Puesto"] = puesto;
            ViewData["Empresa"] = empresa;
            ViewData["Email"] = email;
            ViewData["Telefono"] = telefono;
            ViewData["Direccion"] = direccion;
            ViewData["Cual"] = cual;
            ViewData["Mensaje"] = mensaje;
            ViewData["Privacidad"] = privacidad;
            var qs = "";
            if (string.IsNullOrEmpty(((((System.Web.Mvc.Controller)(this)).Request).Form)["recaptcha_response_field"])) {
                ViewData["QuieroException"] = "<img src=\"/img/error.png\"/> Por favor completa el Captcha.";
            } else {
                var response = new Recaptcha.RecaptchaValidator {
                    Challenge = ((((System.Web.Mvc.Controller)(this)).Request).Form)["recaptcha_challenge_field"],
                    Response = ((((System.Web.Mvc.Controller)(this)).Request).Form)["recaptcha_response_field"],
                    PrivateKey = "6LfumgcTAAAAAG4_s8P4MPcePXs8Oaoi_QItaIT6",
                    RemoteIP = GetUserIPAddress()
                }.Validate();
                if (!response.IsValid)
                    ViewData["QuieroException"] = "<img src=\"/img/error.png\"/> Hubo un error al validar el Captcha.";
            }
            if (string.IsNullOrEmpty(nombre) || string.IsNullOrEmpty(puesto) || string.IsNullOrEmpty(empresa) || string.IsNullOrEmpty(email) ||
                string.IsNullOrEmpty(telefono) || string.IsNullOrEmpty(direccion) ||
                ((string.IsNullOrEmpty(asunto) || asunto == "Selecciona una opción") || (asunto == "Otro" && string.IsNullOrEmpty(cual))) ||
                (string.IsNullOrEmpty(empleados) || asunto == "Selecciona el número de empleados") || string.IsNullOrEmpty(mensaje))
                ViewData["Exception"] = "<img src=\"/img/error.png\"/> Por favor llena todos los campos.";
            else {
                if (!regex.IsMatch(email)) ViewData["Exception"] = "<img src=\"/img/error.png\"/> La dirección de correo electrónico no es v&aacute;lida.";
                ViewData[asunto] = "selected";
                ViewData[empleados] = "selected";
                if (asunto == "Otro") ViewData["Call"] = " onload='call();' ";
            }
            if (privacidad == null) {
                ViewData["Exception"] =
                        "<img src=\"/img/error.png\"/> Por favor, lee y acepta nuestro aviso de privacidad.";
            }
            if (ViewData.ContainsKey("Exception")) return View();
            if (Request.QueryString.Count != 0)
                qs = Request.QueryString.AllKeys.Aggregate(QueryStringInfo, (current, data) => current + string.Format("<p><b>{0}:</b>&nbsp;{1}</p>", data, Request.QueryString[data]));

            var msg = string.Format(Template, nombre, puesto, empresa, email, telefono, direccion, asunto == "Otro" ? cual : asunto, mensaje, qs);
            ViewData["Success"] = SendEmail(msg, "Contacto Atención a clientes Maxcom", email);
            if ((string)ViewData["Success"] == "OK")
                return Redirect("/Gracias");
            return View();
        }
Beispiel #36
0
        private bool IsValidCustom(string  challengeValue, string responseValue)
        {
            if (string.IsNullOrWhiteSpace(challengeValue) || string.IsNullOrWhiteSpace(responseValue))
                return false;
            Recaptcha.RecaptchaValidator captchaValidtor = new Recaptcha.RecaptchaValidator
            {
                PrivateKey = Convert.ToString("6LdoxNQSAAAAAJdWATlAmxo6S7apKJ9XpqWMoI0u"), // Get Private key of the CAPTCHA from Web.config file.
                RemoteIP = HttpContext.Current.Request.UserHostAddress,
                Challenge = challengeValue,
                Response = responseValue
            };

            Recaptcha.RecaptchaResponse recaptchaResponse = captchaValidtor.Validate(); // Send data about captcha validation to reCAPTCHA site.
            return recaptchaResponse.IsValid;
        }