I am trying to implement Googles reCaptcha on my MVC ASP.net project following the instructions found on the third to the top answer of this post, How to implement reCaptcha for ASP.NET MVC?. Currently I have downloaded and included the proper dependencies
using reCAPTCHA.MVC;
My login method looks like :
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
[CaptchaValidator(
PrivateKey = "your private reCaptcha Google Key",
ErrorMessage = "Invalid input captcha.",
RequiredMessage = "The captcha field is required.")]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
}
And in my view I am adding the captcha inside my :
@html.beginform(){
@Html.Recaptcha()
@Html.ValidationMessage("ReCaptcha")
}
I also have my public and private keys added into my web.config file.
However when I run everything on the login page, the captcha box shows up, except there is no where to click and I get the error :
"ERROR for site owner: Invalid site key" where the box to click in the captcha box should be.
In addition I have tried to reset the keys but still no luck.