对 java 验证码库的建议
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/810493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Recommendations for java captcha libraries
提问by skaffman
I'm looking for a replacement for JCaptcha, which doesn't seem to be maintained any more, and isn't very good to begin with. The replacement has to integrate nicely with JavaEE webapps.
我正在寻找 JCaptcha 的替代品,它似乎不再维护,而且一开始也不是很好。替代品必须与 JavaEE webapps 很好地集成。
As I can see it, there are three options:
如我所见,有三个选项:
- JCaptcha - No longer maintained, crude API
- SimpleCaptcha - much nicer API, nicer captchas, but seems to be Java6 only
- ReCaptcha - easy to use, uses remote web-service to generate captchas, but not much control over look and feel
- JCaptcha - 不再维护,粗糙的 API
- SimpleCaptcha - 更好的 API,更好的验证码,但似乎只有 Java6
- ReCaptcha - 易于使用,使用远程网络服务生成验证码,但对外观和感觉没有太多控制
Has anyone used any others, that they'd recommend?
有没有人用过其他的,他们推荐的?
采纳答案by Francis
ReCaptchais the only captcha you should use, because it's the only captcha that makes the world better (improve OCR results to old text), with almost unlimited database.
ReCaptcha是您应该使用的唯一验证码,因为它是唯一可以让世界变得更美好(将 OCR 结果改进为旧文本)的验证码,并且具有几乎无限的数据库。
All other captchas are usually limited by its database, or do nothing good to this world.
所有其他验证码通常受其数据库的限制,或者对这个世界没有任何好处。
EDIT :: I found steps how to implement captcha using recaptcha.
编辑 :: 我找到了如何使用 recaptcha 实现验证码的步骤。
You can check both Online and Offline captcha using java here
您可以在此处使用 java 检查在线和离线验证码
回答by Mike
What happens when ReCaptcha is down/unavailable? Does your service simply stop? Do you simply stop signing people up when it's down? Do you allow users to sign up even if ReCaptcha isn't running? If so, what are the security implications of this? Especially if you use CAPTCHA for more than just signup, e.g. reset password forms, login forms, ... which would not be acceptable to use without the CAPTCHA component.
当 ReCaptcha 关闭/不可用时会发生什么?您的服务是否只是停止?当它关闭时,您是否只是停止让人们注册?即使 ReCaptcha 未运行,您是否允许用户注册?如果是这样,这对安全有什么影响?尤其是如果您使用 CAPTCHA 不仅仅是为了注册,例如重置密码表单、登录表单……如果没有 CAPTCHA 组件,这些将是不可接受的。
The Java world of CAPTCHAs is in a sad state, with SimpleCaptcha seemingly the best solution for those of us out there that cannot accept a hosted service.
CAPTCHA 的 Java 世界处于悲惨的状态,对于我们这些无法接受托管服务的人来说,SimpleCaptcha 似乎是最好的解决方案。
回答by Jon Stevens
I created http://kaptcha.googlecode.combefore recaptcha became as popular as it is today. It also offers you the ability to host it yourself, which may be necessary in some situations.
在 recaptcha 变得像今天这样流行之前,我创建了http://kaptcha.googlecode.com。它还为您提供了自己托管它的能力,这在某些情况下可能是必要的。
Kaptcha is a heavily modified and updated version of SimpleCaptcha and supports JDK5/6.
Kaptcha 是 SimpleCaptcha 的大量修改和更新版本,支持 JDK5/6。
回答by Sasi
Kaptcha is a nice alternative to Recaptcha if you are looking to host your own captcha service instead of relying on a third party captcha service (like recaptcha).
如果您希望托管自己的验证码服务而不是依赖第三方验证码服务(如 recaptcha),则 Kaptcha 是 Recaptcha 的不错替代方案。
回答by jchilders
I am the author of SimpleCaptcha. While I would recommend -- for humanity's sake -- using ReCaptcha where you can, I provided SimpleCaptcha because some organizations have policies which prohibit libraries like ReCaptcha. SimpleCaptcha is meant to be entirely stand-alone, with no external dependencies: as long as you are in a J2EE container, you should be good.
我是SimpleCaptcha的作者。虽然我会建议——为了人类的缘故——尽可能使用 ReCaptcha,但我提供了 SimpleCaptcha,因为一些组织的政策禁止像 ReCaptcha 这样的库。SimpleCaptcha 是完全独立的,没有外部依赖:只要您在 J2EE 容器中,就应该很好。
Also, SimpleCaptcha is now available for either Java 1.5 or Java 6.
此外,SimpleCaptcha 现在可用于 Java 1.5 或 Java 6。
回答by Tilman Hausherr
SimpleCaptcha is really nice and easy to use.
SimpleCaptcha 非常好用且易于使用。
Here's an example how to use SimpleCaptcha with JSF 2.0 (the homepage has an example for JSP)
这是一个如何在 JSF 2.0 中使用 SimpleCaptcha 的示例(主页有一个 JSP 示例)
Note that I'm not even bothering to store the captcha value in the bean, I'm only validating it.
请注意,我什至不想在 bean 中存储验证码值,我只是在验证它。
The bean:
豆:
// imports missing here
@ManagedBean
@SessionScoped
public class LoginBean implements Serializable
{
public void validateCaptcha(FacesContext context,
UIComponent componentToValidate,
Object value)
throws ValidatorException
{
HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
Captcha secretcaptcha = (Captcha) session.getAttribute(Captcha.NAME);
if (secretcaptcha.isCorrect(value.toString()))
return;
// optional: clear field
((HtmlInputText) componentToValidate).setSubmittedValue("");
throw new ValidatorException(new FacesMessage("Captcha does not match"));
}
}
The relevant segment of the facelet:
facelet 的相关部分:
<h:form id="CaptchaForm">
Type this: <br/>
<h:graphicImage id="CaptchaImgID" value="/simpleCaptcha.png"/> <br/>
<h:inputText id="CaptchaID"
required="true"
requiredMessage="Captcha missing"
validator="#{loginBean.validateCaptcha}"
validatorMessage="Captcha does not match"
immediate="true">
</h:inputText>
<br/>
<h:commandButton value="Check"/>
<p/>
<!-- message for the input field -->
<h:message id="CaptchaMsgID" for="CaptchaID" style="color:red" />
</h:form>
The relevant segment of the web.xml:
web.xml 的相关部分:
<servlet>
<servlet-name>SimpleCaptcha</servlet-name>
<servlet-class>nl.captcha.servlet.SimpleCaptchaServlet</servlet-class>
<init-param>
<param-name>captcha-width</param-name>
<param-value>250</param-value>
</init-param>
<init-param>
<param-name>captcha-height</param-name>
<param-value>75</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SimpleCaptcha</servlet-name>
<url-pattern>/simpleCaptcha.png</url-pattern>
</servlet-mapping>
Enjoy :-)
享受 :-)
回答by Srini K
I was able to get source (one by one from browser, not GIT :-( )and build with 1.5. I had a problem with the JDK 1.5 version throwing up the bad class version error ( the one that comes up when compiled with older java version is messed up) which was resolved when I copied the jar I built myself and it works like a charm. I would strongly advise anyone to use this. I tried jcaptcha and I must say it sucks.. the visitors to the web shouldnt have to struggle to verify the code in the image, that defeats the purpose....
我能够获取源代码(从浏览器一个一个,而不是 GIT :-( )并使用 1.5 构建。我遇到了 JDK 1.5 版本的问题,抛出了错误的类版本错误(使用旧版本编译时出现的错误) java 版本搞砸了),当我复制自己构建的 jar 时解决了这个问题,它的作用就像一个魅力。我强烈建议任何人使用它。我尝试了 jcaptcha,我必须说它很糟糕......网络访问者不应该必须努力验证图像中的代码,这违背了目的......