/// <summary>
/// This value will be true if the user passes the test or if the test is unable
/// to run for any reason.
/// </summary>
private bool UserIsHuman
{
get
{
bool isHuman = true; // assume human until proven otherwise
lblResult.Text = "";
// issues in communication with the server will be treated as
// successful validation.
try
{
WebClient client = new WebClient();
NameValueCollection postParms = new NameValueCollection();
postParms.Add("secret", "xxx" );
postParms.Add("response", Request.Params["g-recaptcha-response"]);
String respString = Encoding.UTF8.GetString(resp);
JavaScriptSerializer jss = new JavaScriptSerializer();
dynamic recapVal = jss.DeserializeObject(respString);
bool recapSuccess = false;
recapSuccess = recapVal["success"];
if ((!recapSuccess) ||
(!HttpContext.Current.Request.Url.Host.Equals(recapVal["hostname"])) )
{
isHuman = false;
}
}
catch (Exception)
{
// ignore it.
}
return isHuman;
}
}