Calls the reCAPTCHA server to validate the answer to a reCAPTCHA challenge. Normally, you will use the RecaptchaControl class to insert a web control on your page. However
Exemple #1
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.Response == null)
                        {
                            this.recaptchaResponse = RecaptchaResponse.InvalidResponse;
                        }
                        else
                        {
                            this.recaptchaResponse = validator.Validate();
                        }
                    }
                }
            }
            else
            {
                this.recaptchaResponse = RecaptchaResponse.Valid;
            }
        }
        public void Validate()
        {
            if (Page.IsPostBack && Visible && Enabled && !SkipRecaptcha)
            {
                if (recaptchaResponse == null)
                {
                    if (Visible && Enabled)
                    {
                        RecaptchaValidator validator = new RecaptchaValidator
                        {
                            VerifyUrl  = VerifyUrl,
                            PrivateKey = PrivateKey,
                            RemoteIP   = Page.Request.UserHostAddress,
                            Response   = Context.Request.Form[ResponseField],
                            Proxy      = Proxy
                        };

                        if (validator.Response == null)
                        {
                            recaptchaResponse = RecaptchaResponse.InvalidResponse;
                        }
                        else
                        {
                            recaptchaResponse = validator.Validate().GetAwaiter().GetResult();
                        }
                    }
                }
            }
            else
            {
                recaptchaResponse = RecaptchaResponse.Valid;
            }
        }
        /// <summary>
        /// Perform validation of reCAPTCHA.
        /// </summary>
        public void Validate()
        {
            if (Page.IsPostBack && Visible && Enabled && !SkipRecaptcha)
            {
                if (recaptchaResponse == null)
                {
                    if (Visible && Enabled)
                    {
                        RecaptchaValidator validator = new RecaptchaValidator
                        {
                            VerifyUrl  = VerifyUrl,
                            PrivateKey = PrivateKey,
                            RemoteIP   = Page.Request.UserHostAddress,
                            Response   = Context.Request.Form[ResponseField],
                            Proxy      = Proxy
                        };

                        //validator.Challenge = Context.Request.Form[RECAPTCHA_CHALLENGE_FIELD];
                        if (validator.Response == null)
                        {
                            recaptchaResponse = RecaptchaResponse.InvalidResponse;
                        }
                        else
                        {
                            recaptchaResponse = validator.Validate();
                        }
                    }
                }
            }
            else
            {
                recaptchaResponse = RecaptchaResponse.Valid;
            }
        }
        /// <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];

                        //recaptcha will add a textarea element with id='g-recaptcha-response' for every recaptcha instance
                        //this means if we have more than one on a page, the validation doesn't always work
                        // so, by looping through all form keys with the id 'g-recaptcha-response' and only using the ones
                        // with a value, we're sure to validate properly.
                        // we will then pass the final value to recaptcha to make sure it's valid
                        string response = string.Empty;
                        foreach (string key in Context.Request.Form.AllKeys)
                        {
                            if (key.StartsWith(RECAPTCHA_RESPONSE_FIELD))
                            {
                                if (!String.IsNullOrWhiteSpace(Context.Request.Form[key]))
                                {
                                    response = Context.Request.Form[key];
                                }
                            }
                        }

                        validator.Response = response;
                        validator.Proxy = this.proxy;

                        if (validator.Response == null)
                        {
                            this.recaptchaResponse = RecaptchaResponse.InvalidResponse;
                        }
                        else
                        {
                            this.recaptchaResponse = validator.Validate();
                        }
                    }
                }
            }
            else
            {
                this.recaptchaResponse = RecaptchaResponse.Valid;
            }
        }
        /// <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;
            }
        }