【原创随笔】强大的谷歌开源免费验证码reCAPTCHA

 

1,首先访问http://code.google.com/intl/zh-CN/apis/recaptcha/intro.html,然后点击左侧相应语言,博主示例用的jsp,所以下载jar包,可直接【点此下载jar包】解压zip中的recaptcha4j-0.0.7.jar至web项目lib下。

2,访问https://www.google.com/recaptcha/admin/create并用google账户登录,在文本框输入自己网站的网址,如global-key.mycompany.com ,点击create key,生成Public Key和Private Key。

3,在jsp中编写示例form

 <%@ page import="net.tanesha.recaptcha.ReCaptcha" %>
<%@ page import="net.tanesha.recaptcha.ReCaptchaFactory" %>

<html>
<body>
<form action="" method="post">
<%
ReCaptcha c
= ReCaptchaFactory.newReCaptcha("填入之前生成的public_key", "填入之前生成的private_key", false);
out.print(c.createRecaptchaHtml(
null, null));
%>
<input type="submit" value="submit" />
</form>
</body>
</html>

4,编写示例服务端接收校验

<%@ page import="net.tanesha.recaptcha.ReCaptchaImpl" %>
<%@ page import="net.tanesha.recaptcha.ReCaptchaResponse" %>

<html>
<body>
<%
String remoteAddr = request.getRemoteAddr();
ReCaptchaImpl reCaptcha
= new ReCaptchaImpl();
reCaptcha.setPrivateKey(
"填入之前生成的private_key");

String challenge = request.getParameter("recaptcha_challenge_field");
String uresponse = request.getParameter("recaptcha_response_field");
ReCaptchaResponse reCaptchaResponse
= reCaptcha.checkAnswer(remoteAddr, challenge, uresponse);

if (reCaptchaResponse.isValid()) {
out.print(
"Answer was entered correctly!");
}
else {
out.print(
"Answer is wrong");
}
%>
</body>
</html>




转载于:https://www.cnblogs.com/live365wang/archive/2012/01/13/2321548.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值