驗證碼的功能實現

2021-07-03 23:13:36 字數 2744 閱讀 2279

1.介面採用的js為extjs,

在extjs的view中的login資料夾中,有乙個form.js,驗證碼部分的**是:

xtype: ' fieldcontainer ',

layout: ' hbox ',

items: [,,

, listeners :

}},autoel:}]

2.建立systemusercontroller 。

在這個controller中寫入介面 /getvalidationcode

// 隨機產生88個干擾點,使圖象中的認證碼不易被其它程式探測到

for (int i = 0; i < 20; i++)

// 將認證碼存入session

// 圖象生效

g.dispose();

endtime = system.currenttimemillis();

//測試影象輸出時間

begintime = system.currenttimemillis();

// 輸出圖象到頁面

endtime = system.currenttimemillis();

/*** 使用jpegimageencoder將驗證碼輸出到頁面

*///測試影象輸出-new檔案時間

begintime = system.currenttimemillis();

servletoutputstream out = response.getoutputstream();

pngimageencoder encoder = new pngimageencoder(out, org.apache.xmlgraphics.image.codec.png.pngencodeparam.getdefaultencodeparam(image));

encoder.encode(image);

out.close();

endtime  =  system.currenttimemillis();

}private  void  shear (graphics  g , int  w1 , int  h1 ,  color  color)

public void shearx(graphics g, int w1, int h1, color color) }}

public void sheary(graphics g, int w1, int h1, color color) }}

/*** 取得合法字元:不能出現如下易混淆的字元: 0(數字)、1(數字)、o(字母)、o(字母)、i、i、l(l)

** @param chartype

* @param count

* @return string

* @throws exception

*/public string getvalidrand(string chartype, int count, random random)

}return "9";//預設數字為9

} else

}return "q";//預設字母為q}}

在verificationcodefilter中,**如下:

public class verificationcodefilter implements filter

public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception

public void destroy()

log log = logfactory.getlog(verificationcodefilter.class) }

驗證碼效果圖如下:

驗證碼功能js實現

onload createcode type text id input1 disabled type text id checkcode class code onclick createcode 看不清楚 span id button1 onclick validate type button ...

php驗證碼功能實現

1.頁面 首頁登陸賬戶 2.php伺服器端 使用php向客戶端輸出一幅隨機的驗證碼 header content type image png w 120 h 30 w 150 h 60 在伺服器端記憶體中建立一幅 img imagecreatetruecolor w,h 繪製隨機顏色的背景 矩形 ...

C 實現驗證碼功能

1 建立隨機數生成器 ran程式設計客棧dom 2 使用for迴圈4次 驗證碼四個字元 3 將4個隨機字母隨機數字連線成乙個字串 4 將鏈結好的字串寫入label中 所用到的屬性,迴圈以及資料型別的轉換 具體 如下 using system using system.collections.gene...