導航:首頁 > 編程語言 > java驗證碼干擾線

java驗證碼干擾線

發布時間:2025-07-14 19:01:30

A. 求一個java語言編寫的gif動態驗證碼 就是百度注冊用戶的那種

這個問題有點難度,PHP的好實現,但是java的就不那麼好實現了,目前我正在搞

B. 怎樣用java實現驗證碼

現在許多系統的注冊 登錄或者發布信息模塊都添加的隨機驗證碼功能 就是為了避免自動注冊程序或者自動發布程序的使用

驗證碼實際上就是隨機選擇一些字元以圖片的形式展現在頁面上 如果進行提交操作的同時需要將圖片上的字元同時提交 如果提交的字元與伺服器session保存的不同 則認為提交基數信息無效 為了避免自動程序分析解析圖片 通常會在圖片上隨機生成一些干擾線或者將字元進行扭曲 增加自動識別驗證碼的難度

在這里 我們使用java實現驗證碼

<%@ page contentType= image/jpeg import= java awt * java awt image * java util * javax imageio * %>

<%!

Color getRandColor(int fc int bc){//給定范圍獲得隨機顏色

Random random = new Random();

if(fc> ) fc= ;

租鋒做if(bc> ) bc= ;

int r=fc+random nextInt(bc fc);

int g=fc+random nextInt(bc fc);

int b=fc+random nextInt(bc fc);

return new Color(r g b);

}

%>

<%

//設置頁面不緩存

response setHeader( Pragma No cache );

弊衡response setHeader( Cache Control no cache );

response setDateHeader( Expires );

// 在內存中創建圖象

int width= height= ;

BufferedImage image = new BufferedImage(width height BufferedImage TYPE_INT_RGB);

// 獲取圖形上下文

Graphics g = image getGraphics();

//生成隨機類

Random random = new Random();

// 設定背景色

g setColor(getRandColor( ));

g fillRect( width height);

//設定字體

g setFont(new Font( Times New Roman Font PLAIN ));

// 隨機產生 條干擾線 使圖象中的認證碼不易被其它程序探測到

g setColor(getRandColor( ));

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

{

int x = random nextInt(width);

int y = random nextInt(height);

int xl = random nextInt( );

int yl = random nextInt( );

g drawLine(x y x+xl y+yl);

}

// 取隨機產生的認證碼( 位數字)

String codeList = ;

String sRand= ;

for (int i= ;i< ;i++){

int a=random nextInt(codeList length() );

String rand=codeList substring(a a+ );

sRand+=rand;

// 將認證碼顯示到圖象中

g setColor(new Color( +random nextInt( ) +random nextInt( ) +random nextInt( )));//調用函數出來的顏色相同 可能是因為種子太接近 所以只能直接生成

g drawString(rand *i+ );

}

// 將認證碼存入SESSION

session setAttribute( rand sRand);

// 圖象生效

g dispose();

// 輸出圖象到頁面

ImageIO write(image JPEG response getOutputStream());

out clear();

out = pageContext pushBody();

lishixin/Article/program/Java/hx/201311/25536

閱讀全文

與java驗證碼干擾線相關的資料

熱點內容
論語是由孔子編譯而成的對嗎 瀏覽:788
加密超級大師打不開文件 瀏覽:227
單片機編譯出現not 瀏覽:377
crv大屏安卓mv是什麼格式 瀏覽:98
python二進制的讀取和寫入 瀏覽:56
gz解壓縮命令 瀏覽:656
金工實習數控車床編程 瀏覽:116
美團上的伺服器是什麼意思 瀏覽:624
谷歌在英國倫敦的程序員的工資 瀏覽:690
windows系統的雲伺服器 瀏覽:376
foxitpdfeditor水印 瀏覽:504
phpsocket郵件 瀏覽:264
jsp小區物業管理系統源碼 瀏覽:480
列印機怎麼掃描pdf 瀏覽:280
電子表格如何加密解密 瀏覽:664
我的世界國際服怎麼創伺服器低延遲 瀏覽:632
建設銀行app怎麼知道自己是幾類卡 瀏覽:309
安卓手機怎麼設置到時間睡覺提醒 瀏覽:540
如何加密一個人微信聊天 瀏覽:180
374的源碼 瀏覽:362