導航:首頁 > 源碼編譯 > java驗證碼識別演算法

java驗證碼識別演算法

發布時間:2024-10-16 16:41:06

A. java做驗證碼生成的4位隨機數(例如1234)和兩個隨機數相加(例如5+2)的圖片哪個更好請知道的人給出原理

要看你圖片生成具體演算法...
如果只是一個簡單的背景+數字,那就不如4位隨機數字復雜。同用機器人(或者說是heike)來輸入驗證碼的難度一樣。

如果圖片是由對應隨機數字的點矩陣組成。那5+2之類的圖片相加效果要更好。因為要破解點陣的難度很大。但是從生成效率上這個要低一點。

個人覺得普通安全要求的1234足夠了。。。

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

C. java 登陸時的驗證碼怎麼做

後台寫一個生成圖片隨機的代碼,生成圖片給前台。切換圖片的時候,使用ajax獲取圖片數據就行。
附上生成圖片的代碼
public class ValidateCode {

private int width=180;
private int height=60;
private int codeCount = 4;
private int x = 0;
private int codeY;
private String Code;
private BufferedImage buffImg;
static char[] codeSequence = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', 'o', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
private int fontHeight;

public ValidateCode() {
x = width / (codeCount + 2);
fontHeight = height - 2;
codeY = height - 4;
CreateCode();
}

public void CreateCode(){

// 定義圖像buffer
BufferedImage buffImg = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImg.createGraphics();
// 創建一個隨機數生成器類
Random random = new Random();

// 將圖像填充為白色
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);

// 創建字體,字體的大小應該根據圖片的高度來定。
Font font = new Font("Fixedsys", Font.PLAIN, fontHeight);
// 設置字體。
g.setFont(font);

// 畫邊框。
g.setColor(Color.BLACK);
g.drawRect(0, 0, width - 1, height - 1);

// randomCode用於保存隨機產生的驗證碼,以便用戶登錄後進行驗證。
StringBuffer randomCode = new StringBuffer();
int red = 0, green = 0, blue = 0;

// 隨機產生codeCount數字的驗證碼。
for (int i = 0; i < codeCount; i++) {
// 得到隨機產生的驗證碼數字。
String strRand = String.valueOf(codeSequence[random.nextInt(62)]);
// 產生隨機的顏色分量來構造顏色值,這樣輸出的每位數字的顏色值都將不同。
red = random.nextInt(255);
green = random.nextInt(255);
blue = random.nextInt(255);

// 用隨機產生的顏色將驗證碼繪制到圖像中。
g.setColor(new Color(red, green, blue));
g.drawString(strRand, (i ) * x+20, codeY);

// 將產生的四個隨機數組合在一起。
randomCode.append(strRand);
}
this.Code=randomCode.toString().toUpperCase();
this.buffImg=buffImg;

}

public String getCode() {
return Code;
}

public void setCode(String code) {
Code = code;
}

public BufferedImage getBuffImg() {
return buffImg;
}

public void setBuffImg(BufferedImage buffImg) {
this.buffImg = buffImg;
}
}

D. java簡訊驗證碼要注意什麼問題

1、時間間隔

java簡訊驗證碼並不是你請求幾次都可以的。一般來講在同一個時刻同一部手機發送的同一個請求,一般次數上不會超過三次,時間間隔上會有一分鍾的限定,這是為了避免有些用戶頻繁無效的胡亂點擊或惡意搗亂,影響正常的系統工作,讓有需求的朋友無法正常完成驗證。

2、次數限制

如果遇到有些用戶總是大量的向後台發送請求,次數過多,頻率過大,同一個手機號一天的時間里,超過了一定次數的請求數,那麼該手機號會被認定為一個危險號,有可能會被系統列入黑名單之中,使得下次將無法實現請求驗證。

3、錯誤限定

當用戶對於同個類型的需求進行不斷的驗證,比如說更改密碼、注冊時發送的java簡訊驗證碼,在輸入時的錯誤次數也是有限制的。因為正常、規范的簡訊驗證碼的發送只用很短時間用戶就可以准確接收到,但如果用戶總是不能正確輸入,次數超過了三次的話,就會讓其驗證碼無效,避免有人惡意嘗試輸入,確保用戶的賬戶安全。

簡訊驗證碼在我們日常生活中扮演了及其重要的地位,是保障我們現在互聯網信息的主流安全手段,因此在開發java簡訊驗證碼以及後期的維護中,都不可忽略其安全性。java簡訊驗證碼接入廣東第五大道還可以,提供簡訊驗證碼測試。

E. 用java隨機生成四位驗證碼,只求編程代碼

我自己做的系磨廳統裡面用作驗證碼的JSP的
<%@page contentType="image/jpeg;charset=utf-8"%>
<%@page import="java.util.*,java.awt.*,java.awt.image.*,javax.imageio.*" %>
<%@ page import="java.io.OutputStream" %>
<html>
<body>
<%!
Color getRandColor(int fc,int bc)
{
Random rd=new Random();
if(fc>255) fc=255;
if(bc>255) bc=255;
int red=fc+rd.nextInt(bc-fc);
int green=fc+rd.nextInt(bc-fc);
int blue=fc+rd.nextInt(bc-fc);
return new Color(red,green,blue);
}
%>
<%
Random r=new Random();
response.addHeader("Pragma","No-cache");
response.addHeader("Cache-Control","no-cache");
response.addDateHeader("expires",0);
int width=90;
int height=23;
BufferedImage pic=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics gc=pic.getGraphics();
gc.setColor(getRandColor(200,250));
gc.fillRect(0,0,width,height);
String[] rNum ={"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f",
"g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w",
"耐游神x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N",
"O","P","Q","R","S","T","U","V","W","X","Y","Z"};
int[] style = {Font.PLAIN,Font.BOLD,Font.ITALIC,Font.PLAIN+Font.BOLD,
Font.BOLD+Font.ITALIC,Font.PLAIN+Font.ITALIC,Font.PLAIN+Font.BOLD+Font.ITALIC};
gc.setColor(Color.WHITE);
gc.drawLine(0,30,90,10);
gc.setColor(getRandColor(160,200));
for (int i=0;i<昌虧50;i++)
{
int x = r.nextInt(width);
int y = r.nextInt(height);
int xl = r.nextInt(10);
int yl = r.nextInt(10);
gc.drawLine(x,y,x+xl,y+yl);
}
gc.setColor(getRandColor(60,150));
String rt = "";
for(int i=0;i<4;i++){
String temp = rNum[r.nextInt(62)];
rt = rt+temp;
gc.setFont(new Font("Times New Roman",style[r.nextInt(7)],15));
gc.drawString(temp,5+i*15+r.nextInt(10),10+r.nextInt(10));
}
gc.dispose();
session.setAttribute("randNum",rt);
OutputStream os=response.getOutputStream();
ImageIO.write(pic,"JPEG",os);
System.out.println("當前驗證碼為:"+session.getAttribute("randNum"));
os.flush();
os.close();
os=null;
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
%>
</body>
</html>

閱讀全文

與java驗證碼識別演算法相關的資料

熱點內容
香港雲伺服器1m帶寬嗎 瀏覽:366
如何打開老手機內存卡加密 瀏覽:850
單片機8腳5v 瀏覽:58
防止反編譯技術 瀏覽:489
網關的加密方式用哪個 瀏覽:232
加密便簽在哪裡找小米 瀏覽:527
對數函數的預演算法則 瀏覽:893
會計基礎教材pdf 瀏覽:408
怎麼用蘋果平板登安卓賬號王者 瀏覽:379
蘋果怎麼下rosi的app 瀏覽:488
單片機usb模塊作用 瀏覽:936
拿破崙傳pdf 瀏覽:884
Java7程序設計 瀏覽:400
黑馬程序員百度雲 瀏覽:559
java驗證碼識別演算法 瀏覽:758
單片機共陽極數碼管0到9重復 瀏覽:939
pdf如何圖片格式 瀏覽:381
龍虎榜接收數據器源碼 瀏覽:646
谷歌雲盤鏈接加密 瀏覽:470
ascll轉換java 瀏覽:468