Created
June 18, 2017 15:10
-
-
Save MajidSafari/32e88d57189eedeedd7e6c5f628a61b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string EncodedResponse = Request.Form["g-Recaptcha-Response"]; | |
bool IsCaptchaValid = (ReCaptchaClass.Validate(EncodedResponse) == "True" ? true : false); | |
if (IsCaptchaValid) { | |
//Valid Request | |
} | |
public class ReCaptchaClass | |
{ | |
public static string Validate(string EncodedResponse) | |
{ | |
var client = new System.Net.WebClient(); | |
string PrivateKey = "6LcH-v8SerfgAPlLLffghrITSL9xM7XLrz8aeory"; | |
var GoogleReply = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", PrivateKey, EncodedResponse)); | |
var captchaResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<ReCaptchaClass>(GoogleReply); | |
return captchaResponse.Success; | |
} | |
[JsonProperty("success")] | |
public string Success | |
{ | |
get { return m_Success; } | |
set { m_Success = value; } | |
} | |
private string m_Success; | |
[JsonProperty("error-codes")] | |
public List<string> ErrorCodes | |
{ | |
get { return m_ErrorCodes; } | |
set { m_ErrorCodes = value; } | |
} | |
private List<string> m_ErrorCodes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment