坏蛋 通过本文主要向大家介绍了java验证码实例,java动态口令验证,java动态验证码,验证java,java短信验证等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
前言
相对来说呢,jpg格式的相对来说容易破解一点,当然也取决于你的干扰元素,元素越复杂,破解也就难度越高,有的加的多,人都识别不出来了,何况人呢。都是概率问题。
GIF格式 + 干扰元素,那么验证码破解难度又上了一个层次
上代码:
/**
* 获取验证码(Gif版本)
* @param response
*/
@RequestMapping(value="getGifCode",method=RequestMethod.GET)
public void getGifCode(HttpServletResponse response,HttpServletRequest request){
try {
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/gif");
/**
* gif格式动画验证码
* 宽,高,位数。
*/
Captcha captcha = new GifCaptcha(146,33,4);
//输出
captcha.out(response.getOutputStream());
HttpSession session = request.getSession(true);
//存入Session
session.setAttribute("_code",captcha.text().toLowerCase());
} catch (Exception e) {
LoggerUtils.fmtError(getClass(),e, "获取验证码异常:%s",e.getMessage());
}
}
</div>
使用挺简单的,但是用了其他人封装的工具类。下面会提供下载链接的。
这些个工具类,还提供了这个气泡版本的jpg格式验证码方式。
代码如下:
/**
* 获取验证码(jpg版本)
* @param response
*/
@RequestMapping(value="getJPGCode",method=RequestMethod.GET)
public void getJPGCode(HttpServletResponse response,HttpServletRequest request){
try {
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpg");
/**
* jgp格式验证码
* 宽,高,位数。
*/
Captcha captcha = new SpecCaptcha(146,33,4);
//输出
captcha.out(response.getOutputStream());
HttpSession session = request.getSession(true);
//存入Session
session.setAttribute("_code",captcha.text().toLowerCase());
} catch (Exception e) {
LoggerUtils.fmtError(getClass(),e, "获取验证码异常:%s",e.getMessage());
}
}
</div>
有兴趣的朋友可以下载源码看看。
vcode-sojson.com(weikejianghu.com).rar
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。
</div>
