kaptcha验证码
@Action("/validimg")
public String validimg() throws Exception {
genernateCaptchaImage();
return null;
}
protected void genernateCaptchaImage() throws IOException {
response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
ServletOutputStream out = response.getOutputStream();
try {
String captchaId = request.getSession(true).getId();
LOGGER.info("当前生产验证码的sessionId为: "+captchaId);
BufferedImage challenge = (BufferedImage) CaptchaServiceSingleton.getInstance().getChallengeForID(
captchaId, request.getLocale());
ImageIO.write(challenge, "jpg", out);
out.flush();
} catch (CaptchaServiceException e) {
} finally {
out.close();
}
}
/**
* JCaptcha的单例
*
* @author fuxingxign
*/
public class CaptchaServiceSingleton {
private static ImageCaptchaService instance = new DefaultManageableImageCaptchaService(
new FastHashMapCaptchaStore(), new RdImageEngine(), 180, 100000, 75000); /*
* private static ImageCaptchaService instance = new DefaultManageableImageCaptchaService( new
* FastHashMapCaptchaStore(), new GMailEngine(), 180, 100000 , 75000);
*/
public static ImageCaptchaService getInstance() {
return instance;
}
}
import java.awt.Color;
import java.awt.Font; import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
import com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator;
import com.octo.captcha.component.image.color.RandomRangeColorGenerator;
import com.octo.captcha.component.image.fontgenerator.FontGenerator;
import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator;
import com.octo.captcha.component.image.textpaster.RandomTextPaster;
import com.octo.captcha.component.image.textpaster.TextPaster;
import com.octo.captcha.component.image.wordtoimage.ComposedWordToImage;
import com.octo.captcha.component.image.wordtoimage.WordToImage;
import com.octo.captcha.component.word.wordgenerator.RandomWordGenerator;
import com.octo.captcha.component.word.wordgenerator.WordGenerator;
import com.octo.captcha.engine.image.ListImageCaptchaEngine;
import com.octo.captcha.image.gimpy.GimpyFactory; public class RdImageEngine extends ListImageCaptchaEngine {
@Override
protected void buildInitialFactories() {
WordGenerator wgen = new RandomWordGenerator("abcdefghijklmnopqrstuvwxyz");
RandomRangeColorGenerator cgen = new RandomRangeColorGenerator(new int[] { 0, 100 }, new int[] { 0, 100 },
new int[] { 0, 100 });
TextPaster textPaster = new RandomTextPaster(Integer.valueOf(4),Integer.valueOf(4), cgen, true);
BackgroundGenerator backgroundGenerator = new UniColorBackgroundGenerator(Integer.valueOf(80), Integer.valueOf(37),
Color.WHITE);
Font[] fontsList = new Font[] { new Font("Arial", 0, 12), new Font("Tahoma", 0, 12),
new Font("Verdana", 0, 12), };
FontGenerator fontGenerator = new RandomFontGenerator(Integer.valueOf(26),Integer.valueOf(26), fontsList); WordToImage wordToImage = new ComposedWordToImage(fontGenerator, backgroundGenerator, textPaster);
this.addFactory(new GimpyFactory(wgen, wordToImage));
} }
kaptcha验证码的更多相关文章
- Java实现验证码制作之一Kaptcha验证码
Kaptcha验证码 是google提供的验证码插件,使用起来相对简单,设置的干扰线以及字体扭曲不易让其他人读取破解. 这里我们需要 导入一个 kaptcha-2.3.jar 下载地址:http:/ ...
- kaptcha验证码插件的使用
kaptcha 是一个非常实用的验证码生成工具.有了它,你可以生成各种样式的验证码,因为它是可配置的.kaptcha工作的原理是调用 com.google.code.kaptcha.servlet.K ...
- kaptcha 验证码组件使用
kaptcha 验证码组件使用简介 kaptcha 是一个非常实用的验证码生成工具.有了它,你可以生成各种样式的验证码,因为它是可配置的.kaptcha工作的原理是调用 com.google.co ...
- KAPTCHA验证码使用步骤
使用kaptcha可以方便的配置: · 验证码的字体 · 验证码字体的大小 · 验证码字体的字体颜色 · 验证码内容的范围(数字,字母,中文汉字!) · 验证码图片的大小,边框,边框粗细,边框颜色 · ...
- kaptcha验证码的使用
使用kaptcha可以方便的配置: 验证码的字体 验证码字体的大小 验证码字体的字体颜色 验证码内容的范围(数字,字母,中文汉字!) 验证码图片的大小,边框,边框粗细,边框颜色 验证码的干扰线(可以自 ...
- jcaptcha和kaptcha验证码使用入门【转】
jcaptcha和kaptcha验证码使用入门 一.jcaptcha验证码使用 jcaptcha使用默认样式生成的验证码比较难以识别,所以需要自定义验证码的样式,包括,背景色.背景大小.字体.字体大小 ...
- kaptcha验证码实现,配合spring boot使用
一.kaptcha介绍 Kaptcha是谷歌放在github上的一个验证码jar包,我们可以简单配置属性实现验证码的验证功能. kaptcha参数设置如下所示: Constant 描述 默认值 kap ...
- google kaptcha 验证码的使用
这边演示下idea+maven+servlet实现谷歌的kaptcha验证码的使用: web.xml, 这边主要是kaptcha验证器, <!DOCTYPE web-app PUBLIC &qu ...
- google kaptcha 验证码组件使用简介
kaptcha 是一个非常实用的验证码生成工具.有了它,你可以生成各种样式的验证码,因为它是可配置的.kaptcha工作的原理是调用 com.google.code.kaptcha.servlet.K ...
- kaptcha验证码组件使用简介
Kaptcha是一个基于SimpleCaptcha的验证码开源项目. 官网地址:http://code.google.com/p/kaptcha/ kaptcha的使用比较方便,只需添加jar包依赖之 ...
随机推荐
- android自定义控件属性
有两种方法为自定义的控件设置属性 . 来自为知笔记(Wiz)
- 【转】Thinkphp框架的项目规划总结和踩坑经验
http://www.360doc.com/content/16/1206/22/466494_612576533.shtml
- tips server ssh 正向 反向 代理
1. ssh userxxxxname@115.28.87.102 (直接使用ssh的连接方式连接到远程主机,而不是使用http,ftp等方式连接到具体远程主机) ...
- Linuxmint:MySQL安装指南(转贴)
这篇文章来自以下网站:http://wiki.ubuntu.com.cn/MySQL. 安装MySQL sudo apt-get install mysql-server 这个应该很简单了,而且我觉得 ...
- C# WeakReference(弱引用)
WeakReference(弱引用)我们平常用的都是对象的强引用,如果有强引用存在,GC是不会回收对象的.我们能不能同时保持对对象的引用,而又可以让GC需要的时候回收这个对象呢?.NET中提供了Wea ...
- 第3章 MFC框架程序剖析
参考: https://blog.csdn.net/u014162133/article/details/46573873 1. 2.MFC简介:MFC(Microsoft Foundation Cl ...
- (转)HTML5 本地数据库(SQLite) 示例
HTML5 本地数据库(SQLite) 示例 2012-05-07 16:21:13 标签:SQLite HTML5本地数据库 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作 ...
- android hook 框架 ADBI 简介、编译、运行
Android so注入-libinject2 简介.编译.运行 Android so注入-libinject2 如何实现so注入 Android so注入-Libinject 如何实现so注入 A ...
- 动态符号链接的细节 与 linux程序的加载过程
转: http://hi.baidu.com/clivestudio/item/4341015363058d3d32e0a952 值得玩味的一篇分析程序链接.装载.动态链接细节的好文档 导读: by ...
- nginx+lua_module安装
1.LuaJit安装 # cd /usr/local/src # git clone http://luajit.org/git/luajit-2.0.git # cd luajit-2.0 # ma ...