Java中使用patchca生成超炫的验证码
程序员文章站
2023-12-10 17:21:10
官网:
/**
* 验证码
*
* @param width 图片宽度
* @param height 图片高度
* @p...
官网:
/** * 验证码 * * @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(); }
以上所述是小编给大家介绍的java中使用patchca生成超炫的验证码 ,希望对大家有所帮助