public class GoogleReCaptchaChecker {
@Value("${google.recaptcha.url}")
private String url;
@Value("${google.recaptcha.secret-key}")
private String secretKey;
@Value("${google.recaptcha.site-key}")
private String siteKey;
@Autowired
RestTemplate restTemplate;
public Boolean validateGoogleReCaptcha(String reCaptchaResponseStr, String remoteAddr) {
try {
ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey(secretKey);
ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, siteKey, reCaptchaResponseStr);
return reCaptchaResponse.isValid();
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
This is my code for "google recaptcha" validation, but it always returns false, I have no idea about what are the arguments need to be passed. is there any maven dependency to do ReCaptcha validation?. I'm using this net.tanesha.recaptcha4j(version-0.0.7) dependency
If you see the error again then please make sure that you first have Javascript enabled, and that your current browser does not have any extensions/add-ons enabled: Since ReCaptcha is enabled by Google services, using proxies or add-ons that block Google server requests will cause problems (an example being Ghostery)
reCAPTCHA analyzes interactions with the website to detect if they are made by a human or some form of automated abuse. Sometimes, you may see a "failed reCAPTCHA check" error message while trying to create or amend your account. This means the website believes your actions may be those of a bot.
One of the most common reasons why this error occurs is that of an outdated Chrome version. reCAPTCHA will actively look at the browser version before allowing you access. This is applicable to all browser versions, not just Chrome. In this case, the solution is to update Google Chrome to the latest version.
There is a Spring Boot starter project witch will validate reCAPTCHA for you.
You just have to set the captcha validated URLs in your config file.
More on GitHub: https://github.com/Mr-DeWitt/spring-boot-recaptcha
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With