package hirondelle.predict.util;
import hirondelle.web4j.util.Util;
import java.util.logging.Logger;
import net.tanesha.recaptcha.ReCaptchaImpl;
import net.tanesha.recaptcha.ReCaptchaResponse;
public final class Captcha {
public static void init(String aPrivateKey) {
fPrivateKey = aPrivateKey;
if( fPrivateKey.equalsIgnoreCase("NONE") || ! Util.textHasContent(fPrivateKey) ) {
String message =
"You haven't set the CaptchaPrivateKey setting in web.xml. " +
"You must acquire your own private key. See recaptcha.net for more details."
;
fLogger.severe(message);
throw new IllegalArgumentException(message);
}
}
public static boolean isCaptchaValid(String aIpAddress, String aChallenge, String aResponse){
ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey(fPrivateKey);
ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(
aIpAddress, aChallenge, aResponse
);
return reCaptchaResponse.isValid();
}
private static String fPrivateKey;
private static final Logger fLogger = Util.getLogger(Captcha.class);
}