patchca生成超炫的验证码

官网:http://code.google.com/p/patchca/


    /**
     * 验证码
     *
     * @param width  图片宽度
     * @param height 图片高度
     * @param number 验证码数量
     */
    @RequestMapping(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.setFontFactory(ff);
        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();
    }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值