Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding google recaptcha server side verification MVC3

I've been following the google recaptcha instructions and am at the point where I want to add server side verification:

https://developers.google.com/recaptcha/docs/verify

But when I look at that page, I get a description of some of the methods, but not instructions on what exactly I write into my view. What exactly do I write onto my view to call on google's verification?

like image 936
jsmith Avatar asked Feb 11 '26 00:02

jsmith


1 Answers

Make sure you reference Recaptcha in your controller and then validate on the post

@using Recaptcha; // goes in your controller 

This is an example of how to validate server-side

[HttpPost]
[RecaptchaControlMvc.CaptchaValidator]
public ActionResult ForgotPassword(CheckUsernameViewModel model, bool captchaValid, string captchaErrorMessage) {
    if(ModelState.IsValid) {
        if(captchaValid) {
            // do stuff
        }
        ModelState.AddModelError("", captchaErrorMessage);
    }
    return View(model);
}

For all the info, see my posted answer here for the walkthrough to implement correctly.

How to implement Google reCaptcha in an MVC3 application?

like image 154
CD Smith Avatar answered Feb 12 '26 15:02

CD Smith