https://github.com/Dreampie/jfinal-captcha jfinal-captcha是一款驗證嗎插件:html
1 <dependency> 2 <groupId>cn.dreampie</groupId> 3 <artifactId>jfinal-captcha</artifactId> 4 <version>${jfinal-captcha.version}</version> 5 </dependency>
目前剛剛發佈第一個版本0.1:git
1 <jfinal-captcha.version>0.1</jfinal-captcha.version>
使用方法:github
1 /** 2 * 驗證碼 3 */ 4 public void captcha() { 5 int width = 0, height = 0, minnum = 0, maxnum = 0, fontsize = 0, fontmin = 0, fontmax = 0; 6 CaptchaRender captcha = new CaptchaRender(); 7 if (isParaExists("width")) { 8 width = getParaToInt("width"); 9 } 10 if (isParaExists("height")) { 11 height = getParaToInt("height"); 12 } 13 if (width > 0 && height > 0) 14 captcha.setImgSize(width, height); 15 if (isParaExists("minnum")) { 16 minnum = getParaToInt("minnum"); 17 } 18 if (isParaExists("maxnum")) { 19 maxnum = getParaToInt("maxnum"); 20 } 21 if (minnum > 0 && maxnum > 0) 22 captcha.setFontNum(minnum, maxnum); 23 if (isParaExists("fontsize")) { 24 fontsize = getParaToInt("fontsize"); 25 } 26 if (fontsize > 0) 27 captcha.setFontSize(fontsize, fontsize); 28 //干擾線數量 默認0 29 captcha.setLineNum(0); 30 //噪點數量 默認50 31 captcha.setArtifactNum(0); 32 //使用字符 去掉0和o 避免難以確認 33 // captcha.setCode("ABCDEFGHIJKLMNPQRSTUVWXYZ123456789"); 34 //驗證碼在session裏的名字 默認 captcha,建立時間爲:名字_time 35 // captcha.setCaptchaName("captcha"); 36 //驗證碼顏色 默認黑色 37 // captcha.setDrawColor(new Color(255,0,0)); 38 //背景干擾物顏色 默認灰 39 // captcha.setDrawBgColor(new Color(0,0,0)); 40 //背景色+透明度 前三位數字是rgb色,第四個數字是透明度 默認透明 41 // captcha.setBgColor(new Color(225, 225, 0, 100)); 42 //濾鏡特效 默認隨機特效 //曲面Curves //大理石紋Marble //彎折Double //顫動Wobble //擴散Diffuse 43 // captcha.setFilter(CaptchaRender.FilterFactory.Curves); 44 //隨機色 默認黑驗證碼 灰背景元素 45 captcha.setRandomColor(true); 46 render(captcha); 47 } 48 49 // html 50 /captcha?width=128&height=45&fontsize=30&time={{time}}
驗證碼默認使用captcha做爲名稱存在session中,能夠經過setCaptchaName(String name)改變名字session