public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { ValueProviderResult chall = bindingContext.ValueProvider.GetValue("recaptcha_challenge_field"); ValueProviderResult resp = bindingContext.ValueProvider.GetValue("recaptcha_response_field"); if (chall != null && resp != null && !string.IsNullOrEmpty(chall.AttemptedValue) && !string.IsNullOrEmpty(resp.AttemptedValue)) { bindingContext.ModelState.SetModelValue(bindingContext.ModelName + ".recaptcha_challenge_field", chall); bindingContext.ModelState.SetModelValue(bindingContext.ModelName + ".recaptcha_response_field", resp); Recaptcha rec = new Recaptcha { recaptcha_challenge_field = ((string[])chall.RawValue)[0], recaptcha_response_field = ((string[])resp.RawValue)[0] }; try { if (!rec.Verify()) bindingContext.ModelState.AddModelError(bindingContext.ModelName, "You typed the pictured text incorrectly, please try again"); } catch { bindingContext.ModelState.AddModelError(bindingContext.ModelName, "We could not validate you typed the pictured words correctly, please try again"); } return rec; } else { bindingContext.ModelState.AddModelError(bindingContext.ModelName, "Please type the pictured text into the box underneath it"); return null; } }
async public Task <JsonResult> Base(string recaptchaKey, int HourCacheToUser, string hash) { if (string.IsNullOrWhiteSpace(recaptchaKey)) { return(Json(new Text("recaptchaKey == null"))); } if (hash != md5.text($"{HourCacheToUser}:{PasswdTo.salt}")) { return(Json(new Text("hash error"))); } // Проверяем reCAPTCHA if (await Recaptcha.Verify(recaptchaKey, jsonDB.Base.reCAPTCHASecret)) { // Валидные куки string cookie = Engine.core.AntiBot.GetValidCookie(HourCacheToUser, HttpContext.Connection.RemoteIpAddress.ToString()); // Отдаем ответ return(Json(new { result = true, cookie = cookie, HourToCookie = HourCacheToUser })); } // Ошибка return(Json(new Text("Verify == false"))); }
async public Task <JsonResult> LimitRequest(string recaptchaKey, string IP, int ExpiresToMinute, string hash) { if (string.IsNullOrWhiteSpace(recaptchaKey)) { return(Json(new Text("recaptchaKey == null"))); } if (hash != md5.text($"{IP}{ExpiresToMinute}:{PasswdTo.salt}")) { return(Json(new Text("hash error"))); } // Проверяем reCAPTCHA if (await Recaptcha.Verify(recaptchaKey, jsonDB.Base.reCAPTCHASecret)) { // Создаем кеш memoryCache.Set(KeyToMemoryCache.LimitRequestToreCAPTCHA(IP), (0, ExpiresToMinute), TimeSpan.FromMinutes(ExpiresToMinute)); // Отдаем ответ return(Json(new TrueOrFalse(true))); } // Ошибка return(Json(new Text("Verify == false"))); }
async Task <(bool res, object ob)> Verify(string recaptchaKey, string IP, int expires, string hash) { #region Проверка параметров if (string.IsNullOrWhiteSpace(recaptchaKey)) { return(false, new Text("recaptchaKey == null")); } if (string.IsNullOrWhiteSpace(IP)) { IP = HttpContext.Connection.RemoteIpAddress.ToString(); } if (hash != md5.text($"{IP}:{expires}:{PasswdTo.salt}")) { return(false, new Text("hash error")); } #endregion // Проверяем reCAPTCHA if (await Recaptcha.Verify(recaptchaKey, jsonDB.Security.reCAPTCHASecret)) { return(true, null); } // Ошибка return(false, new Text("Verify == false")); }
public ActionResult ProcessRecaptcha(string captchaResponse) { var recaptcha = new Recaptcha(); var result = recaptcha.Verify(captchaResponse); return(Json(result)); }
public ActionResult Index(string name) { var recaptchaResponse = Recaptcha.Verify(); if (!recaptchaResponse.Success) { ModelState.AddModelError("Recaptcha", "Informe que você não é um robô clicando no quadro do reCAPTCHA"); } return(View()); }
protected void BtnGetResult_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(WebAccessCodeTextBox.Text)) { this.ErrorLabel.Text = GetLocalResourceObject("ErrorLabelText").ToString(); } else { if (Convert.ToInt32(Session["numberIncorrectPassword"]) >= 5) { if (String.IsNullOrEmpty(Recaptcha.Response)) { this.ErrorLabel.Text = GetLocalResourceObject("CaptchaNullOrEmpty").ToString(); } else { RecaptchaVerificationResult result = Recaptcha.Verify(); if (result == RecaptchaVerificationResult.Success) { Session["numberIncorrectPassword"] = 0; this.Recaptcha.Style["display"] = "none"; this.ErrorLabel.Text = null; GetResult(); } if (result == RecaptchaVerificationResult.IncorrectCaptchaSolution) { this.ErrorLabel.Text = GetLocalResourceObject("CaptchaIncorrect").ToString(); } else { GetResult(); } } } else { GetResult(); } } }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { ValueProviderResult chall = bindingContext.ValueProvider.GetValue("recaptcha_challenge_field"); ValueProviderResult resp = bindingContext.ValueProvider.GetValue("recaptcha_response_field"); if (chall != null && resp != null && !string.IsNullOrEmpty(chall.AttemptedValue) && !string.IsNullOrEmpty(resp.AttemptedValue)) { bindingContext.ModelState.SetModelValue(bindingContext.ModelName + ".recaptcha_challenge_field", chall); bindingContext.ModelState.SetModelValue(bindingContext.ModelName + ".recaptcha_response_field", resp); Recaptcha rec = new Recaptcha { recaptcha_challenge_field = ((string[])chall.RawValue)[0], recaptcha_response_field = ((string[])resp.RawValue)[0] }; try { if (!rec.Verify()) { bindingContext.ModelState.AddModelError(bindingContext.ModelName, "You typed the pictured text incorrectly, please try again"); } } catch { bindingContext.ModelState.AddModelError(bindingContext.ModelName, "We could not validate you typed the pictured words correctly, please try again"); } return(rec); } else { bindingContext.ModelState.AddModelError(bindingContext.ModelName, "Please type the pictured text into the box underneath it"); return(null); } }
protected void btncaptcha_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(Recaptcha.Response)) { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Captcha cannot be empty.');", true); // Label1.Text = "Captcha casnnot be empty."; } else { RecaptchaVerificationResult verify = Recaptcha.Verify(); if (verify == RecaptchaVerificationResult.Success) { // ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Captcha is correct');", true); if (IsValidName(name.Value)) { if (IsValidDesignation(designation.Value)) { if (IsValidCompany(company.Value)) { if (IsValidEmail(email.Value)) { if (IsItNumber(phone.Value)) { if (name.Value == "" || designation.Value == "" || company.Value == "" || location.Value == "" || website.Value == "" || email.Value == "" || phone.Value == "" || message.Value == "") { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please fill all fields!');", true); return; } else { sendmail(name.Value, designation.Value, company.Value, location.Value, website.Value, email.Value, phone.Value, message.Value); name.Value = null; designation.Value = null; company.Value = null; location.Value = null; website.Value = null; email.Value = null; phone.Value = null; message.Value = null; ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Mail send successfully');", true); } } else { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Invalid Phone No');", true); } } else { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Invalid email address');", true); } } else { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Invalid Company Name');", true); } } else { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Invalid Designation');", true); } } else { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Invalid Name');", true); } } else { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Captcha information not matched');", true); // Label1.Text = "Captcha information not matched"; } } }