recaptcha的验证码新增了alpha composite的新机制取代干扰线,今天用了一些时间在YAN上也实现了这种绘图机制。
使用Java2D的AlphaComposite实现,选用的Rule为alpha 1.0的SrcOut,即通过公式
Ar = As * (1 – Ad )
Cr = Cs * (1 – Ad )
用语言描述就是叠加区域的透明度为0. 使用这种机制必须采用BufferedImage.TYPE_INT_ARGB的图像,并且输出支持alpha通道的格式。
recaptcha的验证码新增了alpha composite的新机制取代干扰线,今天用了一些时间在YAN上也实现了这种绘图机制。
使用Java2D的AlphaComposite实现,选用的Rule为alpha 1.0的SrcOut,即通过公式
Ar = As * (1 – Ad )
Cr = Cs * (1 – Ad )
用语言描述就是叠加区域的透明度为0. 使用这种机制必须采用BufferedImage.TYPE_INT_ARGB的图像,并且输出支持alpha通道的格式。
Yan 新增了一种验证码类型,Web 2.0 图标验证码。用户根据图标的内容和提示的信息,提交验证码。验证码图片如下:

提示文字: Please figure out twitter icons.
用户输入Twitter图标左上角上的字母,即可进行验证。在Yan的测试界面上使用如图:

Web2.0 Icon实际上是Yan中新增的拼图验证码的一个实例,利用拼图验证码可以生成相似的更有创意的验证码。在我的开发环境中生成这样一张图片大约需要80ms。
项目中使用的图标均从互联网收集,遵循CC等协议或经作者授权,详情参考项目中README文件。
祝DAF同学生日快乐。
给Yan的验证码图片服务做了压力测试。测试环境:
Jetty采用默认配置 maxThreads 200。
测试工具:ab (Apache Bench)
分别用10/50/100/200/500/1000并发用户,每个用户请求100次进行测试。结果如下:
| 10 | 50 | 100 | 200 | 500 | 1000 | |
| Requests per second | 487.11 | 472.09 | 442.74 | 421.63 | 408.11 | 326.12 |
| Time per request | 2.05 | 2.12 | 2.26 | 2.37 | 2.45 | 3.07 |
| Transfer rate | 987.91 | 955.54 | 896.85 | 854.31 | 826.25 | 660.45 |

目前对每个请求独立使用JDK的awt实时绘图,吞吐量可以达到400以上,如果稍稍优化一下Jetty的配置,性能还有一定的提升空间。这个结果还是不错的。
I’d like to announce my recent works, a project called Yan Captcha Service written in Java which is aimed to provide whole solutions of captcha for your websites. It will be very easy to use the service because 1. interfaces are based on plain http url; 2. different kinds of usage are supported to fit your requirements; 3. the architecture is open so you can add your own solid implementation of captcha; 4. less coupling with your system. And designed for scalability, currently, it applies JGroups to share sessions (memcached support will be added soon), thus you can setup a cluster for the service.
As you may know, the open-source project is split from my current work-time project because it is more closed to my idea. However, soon we will have the product opened to our thousands (millions ?) of users. I can gain feedback from the challenge and improve the open-source edition.
The code is maintained by open-source scm, mercurial (also known as hg). The project is now hosted on bitbucket.org. You can clone the code to local via:
$ hg clone https://sunng@bitbucket.org/sunng/yan/
To build the project, run this command in root of project directory:
mvn install
To run in a develop environment:
mvn jetty:run
Issue reporting and patches are always welcomed.
Check the wiki pages for more information about the project:
http://bitbucket.org/sunng/yan/wiki/Home
今天又讨论了一种验证码服务的机制,这种机制相对前两天说的简化的验证码生成的部分,由两步生成变成了一步生成,当然由于生成图片的接口直接暴露给用户,存在被刷的可能。

优点:
固定链接,简化了接入,便于接入静态页面;
缺点:
写cookie受到域的限制,只能在相同的域中使用该服务;
验证码接口暴露给用户,可能被穷举
百度和腾讯使用的都是这种方式。

这种方式的优点:

这种方式的优点:
欢迎大家就两种方式发表意见~