zookeeper python接口实例详解
239
2023-05-05
Java中使用patchca生成超炫的验证码
官网:http://code.google.com/p/patchca/
/**
* 验证码
*
* @param width 图片宽度
* @param height 图片高度
* @param number 验证码数量
*/
@RequestMaqIRbHjpping(value = {"/captcha"})
public void captcha(HttpServletRequest request,
HttpServletResponse response, @RequestParam("w") int width, @RequestParam("h") int height, @RequestParam("n") int number) throws IOException {
ConfigurableCaptchaService cs = new ConfigurableCaptchaService();
cs.setColorFactory(new SingleColorFactory(new Color(25, 60, 170)));
cs.setFilterFactory(new CurvesRippleFilterFactory(cs.getColorFactory()));
RandomFontFactory ff = new RandomFontFactory();
ff.setMinSize(30);
ff.setMaxSize(30);
RandomWordFactory rwf = new RandomWordFactory();
rwf.setMinLength(number);
rwf.setMaxLength(number);
cs.setWordFactory(rwf);
cs.setFontFahttp://ctory(ff);
http:// cs.setHeight(height);
cs.setWidth(width);
response.setContentType("image/png");
response.setHeader("Cache-Control", "no-cache, no-store");
response.setHeader("Pragma", "no-cache");
long time = System.currentTimeMillis();
response.setDateHeader("Last-Modified", time);
response.setDateHeader("Date", time);
response.setDateHeader("Expires", time);
ServletOutputStream stream = response.getOutputStream();
String validate_code = EncoderHelper.getChallangeAndWriteImage(cs,
"png", stream);
Subject subject = SecurityUtils.getSubject();
subject.getSession().setAttribute(formAuthenticationFilter.getCaptchaParam(), validate_code);
stream.flush();
stream.close();
}
以上所述是给大家介绍的java中使用patchca生成超炫的验证码 ,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,会及时回复大家的!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~