I use a simple recaptcha helper which i call from the controller, to verify the result with.
public class CaptchaHelper : IInjected
{
private readonly UmbracoHelper umbracoHelper;
public CaptchaHelper(UmbracoHelper umbracoHelper)
{
this.umbracoHelper = umbracoHelper;
}
public string AuthenticateRecaptcha(string response)
{
string secretKey = umbracoHelper.GetDictionaryValue("Google Captcha Secret Key");
var webClient = new WebClient();
var reply =
webClient.DownloadString(
string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}",
secretKey, response));
return reply;
}
}
public class CaptchaResponse
{
[JsonProperty("success")]
public bool Success { get; set; }
[JsonProperty("error-codes")]
public List<string> ErrorCodes { get; set; }
}
When i call the code, for example in my mail helper, i call the helper, and pass the request. And then check on the success status of the response.
string reply = captchaHelper.AuthenticateRecaptcha(Request["g-recaptcha-response"]);
var captchaResponse = JsonConvert.DeserializeObject<CaptchaResponse>(reply);
if (captchaResponse.Success)
{
}