Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- public void Method(MyData data, string challenge, string response)
- {
- string recaptchaValidationUrl = "http://www.google.com/recaptcha/api/verify";
- string privateKey = "MY_RECAPTCHA_PRIVATE_KEY";
- if (!CheckRecaptcha(recaptchaValidationUrl, request.RcChallenge, request.RcResponse, privateKey,
- HttpContext.Current.Request.UserHostAddress))
- {
- return new FindTechResResponse { ErrorMessage = "Invalid captcha code" };
- }
- }
- public static bool CheckRecaptcha(string recaptchaValidationUrl, string challenge, string response, string privateKey, string clientIp)
- {
- using (WebClient webClient = new WebClient())
- {
- NameValueCollection data = new NameValueCollection();
- data["privatekey"] = privateKey;
- data["remoteip"] = clientIp;
- data["challenge"] = challenge;
- data["response"] = response;
- byte[] responseBytes = webClient.UploadValues(recaptchaValidationUrl, "POST", data);
- string responseString = Encoding.UTF8.GetString(responseBytes);
- string isSolvedString = responseString.Split('\n')[0];
- bool isSolved = bool.Parse(isSolvedString);
- return isSolved;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement