當前位置:首頁 » 網頁前端 » web驗證碼
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

web驗證碼

發布時間: 2022-01-14 15:35:17

⑴ java web 項目驗證碼的刷新問題

用js換 img的src就行了啊。
function change(){
document.getElementById("CreateCheckCode").src="PictureCheckCode?"+Math.random();
}
</script>
<img id="CreateCheckCode" src="PictureCheckCode" onclick="change()" />

⑵ java web中驗證碼代碼

生成code.jsp文件的完整代碼如下:

<%@ page language="java" contentType="image/jpeg; charset=gb2312"
pageEncoding="gb2312"%>
<%@ page import="java.awt.*,java.awt.image.*" %>
<%@ page import="java.util.*,javax.imageio.*" %>
<%!
Color getRandColor(int fc,int bc){
Random r=new Random();
if(fc>255) fc=255;
if(bc>200) bc=255;
int red=fc+r.nextInt(bc-fc);
int green=fc+r.nextInt(bc-fc);
int blue=fc+r.nextInt(bc-fc);
return new Color(red,green,blue);
}%>
<% //設置頁面不緩存
response.setHeader("Pragma","No-cache");
response.setHeader("cache-Control","no-cache");
response.setDateHeader("Expires",0);
//創建隨機類
Random r=new Random();
//在內存中創建圖像,寬度,高度
int width=80,height=30;
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);
//設定圖形上下文環境字體
gc.setFont(new Font("Times New Roman",Font.PLAIN,20));
//畫邊框
//gc.setColor(new Color(1));
//gc.drawRect(0,0,width-1,height-1);

//隨機產生200條干擾直線,使圖像中的認證碼不易被其他分析程序探測
gc.setColor(getRandColor(160,200));
for(int i=0;i<200;i++)
{
int x1=r.nextInt(width);
int y1=r.nextInt(height);
int x2=r.nextInt(15);
int y2=r.nextInt(15);
gc.drawLine(x1,y1,x1+x2,y1+y2);
}
//隨即產生100個干擾點
gc.setColor(getRandColor(120,240));
for(int i=1;i<100;i++){
int x=r.nextInt(width);
int y=r.nextInt(height);
gc.drawOval(x,y,0,0);
}
//隨機產生四位數字的驗證碼
String RS="";
String rn="";
for(int i=0;i<4;i++)
{
//產生十以內隨機數字
rn=String.valueOf(r.nextInt(10));
RS+=rn;
//將認證碼用drawString函數顯示到圖像里
gc.setColor(new Color(20+r.nextInt(110),20+r.nextInt(110),20+r.nextInt(110)));//使字體顏色效果明顯
gc.drawString(rn,13*i+16,16);
}
//釋放圖形上下文環境
gc.dispose();
//將認證碼RS存入session中共享
session.setAttribute("random",RS);

//輸出生成後的圖象到頁面
ImageIO.write(pic,"JPEG",response.getOutputStream());

out.clear();
out = pageContext.pushBody();

%>

使用隨即碼的jsp文件中加入下面一句即可
<image src="code.jsp">

⑶ JAVAWEB項目怎麼實現驗證碼

importjava.awt.Color;
importjava.awt.Font;
importjava.awt.Graphics;
importjava.awt.image.BufferedImage;
importjava.io.IOException;
importjava.io.OutputStream;
importjava.util.Random;
importjavax.imageio.ImageIO;

publicclassCode{

//圖片的寬度。
privateintwidth=160;
//圖片的高度。
privateintheight=38;
//驗證碼字元個數
privateintcodeCount=4;
//驗證碼干擾線數
privateintlineCount=20;
//驗證碼
privateStringcode=null;
//驗證碼圖片Buffer
privateBufferedImagebuffImg=null;
Randomrandom=newRandom();

privatebooleantype=false;

publicCode(){

}

publicCode(intwidth,intheight){
this.width=width;
this.height=height;
}

publicCode(intwidth,intheight,intcodeCount){
this.width=width;
this.height=height;
this.codeCount=codeCount;
}

publicCode(intwidth,intheight,intcodeCount,intlineCount){
this.width=width;
this.height=height;
this.codeCount=codeCount;
this.lineCount=lineCount;
}

publicvoidinit(booleantype){
this.type=type;
}

//生成圖片
privatevoidcreatImage(booleantype){
intfontWidth=width/codeCount;//字體的寬度
intfontHeight=height-5;//字體的高度
intcodeY=height-8;

//圖像buffer
buffImg=newBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphicsg=buffImg.getGraphics();
//Graphics2Dg=buffImg.createGraphics();
//設置背景色
g.setColor(getRandColor(200,250));
g.fillRect(0,0,width,height);//設置字體
Fontfont=null;
if(!type)font=newFont("Fixedsys",Font.BOLD,fontHeight);
elsefont=getFont(fontHeight);
g.setFont(font);

//設置干擾線
for(inti=0;i<lineCount/2;i++){
intxs=random.nextInt(width);
intys=random.nextInt(height);
intxe=xs+random.nextInt(width);
intye=ys+random.nextInt(height);
g.setColor(getRandColor(1,255));
if(!type)g.drawLine(xs,ys,xe,ye);
elseshear(g,width,height,getRandColor(1,255));
}

//添加噪點
floatyawpRate=0.01f;//雜訊率
intarea=(int)(yawpRate*width*height);
for(inti=0;i<area;i++){
intx=random.nextInt(width);
inty=random.nextInt(height);

buffImg.setRGB(x,y,random.nextInt(255));
}


Stringstr1=randomStr(codeCount);//得到隨機字元
this.code=str1;
for(inti=0;i<codeCount;i++){
StringstrRand=str1.substring(i,i+1);
g.setColor(getRandColor(1,255));
//g.drawString(a,x,y);
//a為要畫出來的東西,x和y表示要畫的東西最左側字元的基線位於此圖形上下文坐標系的(x,y)位置處

g.drawString(strRand,i*fontWidth+3,codeY);
}


}

//得到隨機字元
privateStringrandomStr(intn){
Stringstr1="";//I和l不要
Stringstr2="";
intlen=str1.length()-1;
doubler;
for(inti=0;i<n;i++){
r=(Math.random())*len;
str2=str2+str1.charAt((int)r);
}
returnstr2;
}

//得到隨機顏色
privateColorgetRandColor(intfc,intbc){//給定范圍獲得隨機顏色
if(fc>255)
fc=255;
if(bc>255)
bc=255;
intr=fc+random.nextInt(bc-fc);
intg=fc+random.nextInt(bc-fc);
intb=fc+random.nextInt(bc-fc);
returnnewColor(r,g,b);
}

/**
*產生隨機字體
*/
privateFontgetFont(intsize){
Randomrandom=newRandom();
Fontfont[]=newFont[5];
font[0]=newFont("Ravie",Font.PLAIN,size);
font[1]=newFont("AntiqueOliveCompact",Font.PLAIN,size);
font[2]=newFont("Fixedsys",Font.PLAIN,size);
font[3]=newFont("WideLatin",Font.PLAIN,size);
font[4]=newFont("GillSansUltraBold",Font.PLAIN,size);
returnfont[random.nextInt(5)];
}

//扭曲方法
privatevoidshear(Graphicsg,intw1,inth1,Colorcolor){
shearX(g,w1,h1,color);
shearY(g,w1,h1,color);
}

privatevoidshearX(Graphicsg,intw1,inth1,Colorcolor){

intperiod=random.nextInt(2);

booleanborderGap=true;
intframes=1;
intphase=random.nextInt(2);

for(inti=0;i<h1;i++){
doubled=(double)(period>>1)
*Math.sin((double)i/(double)period
+(6.2831853071795862D*(double)phase)
/(double)frames);
g.Area(0,i,w1,1,(int)d,0);
if(borderGap){
g.setColor(color);
g.drawLine((int)d,i,0,i);
g.drawLine((int)d+w1,i,w1,i);
}
}

}

privatevoidshearY(Graphicsg,intw1,inth1,Colorcolor){

intperiod=random.nextInt(40)+10;//50;

booleanborderGap=true;
intframes=20;
intphase=7;
for(inti=0;i<w1;i++){
doubled=(double)(period>>1)
*Math.sin((double)i/(double)period
+(6.2831853071795862D*(double)phase)
/(double)frames);
g.Area(i,0,1,h1,0,(int)d);
if(borderGap){
g.setColor(color);
g.drawLine(i,(int)d,i,0);
g.drawLine(i,(int)d+h1,i,h1);
}

}

}publicvoidwrite(OutputStreamsos)throwsIOException{
if(buffImg==null)creatImage(type);
ImageIO.write(buffImg,"png",sos);
//JPEGImageEncoderencoder=JPEGCodec.createJPEGEncoder(sos);
//encoder.encode(buffImg);
sos.close();
}

publicBufferedImagegetBuffImg(){
if(buffImg==null)creatImage(type);
returnbuffImg;
}

publicStringgetCode(){
returncode.toLowerCase();
}

//使用方法
/*publicvoidgetCode3(HttpServletRequestreq,HttpServletResponseresponse,HttpSessionsession)throwsIOException{
//設置響應的類型格式為圖片格式
response.setContentType("image/jpeg");
//禁止圖像緩存。
response.setHeader("Pragma","no-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires",0);


CreateImageCodevCode=newCreateImageCode(100,30,5,10);
session.setAttribute("code",vCode.getCode());
vCode.write(response.getOutputStream());
response.flushBuffer();
}*/

}

⑷ 怎樣破解web圖形驗證碼

利用JavaScript破解驗證碼
近日,網上驚現可以破解驗證碼的JavaScript腳本——GreaseMonkey!由「Shaun Friedle」開發的這段腳本可以輕松搞定Megaupload站點的CAPTCHA。如果您不相信的話,可以到http://herecomethelizards.co.uk/mu_captcha/親自嘗試一下!

現在,Megaupload站點提供的CAPTCHA在上述代碼面前已經敗下陣來,說實話,這里的驗證碼設計的不不太好。但更有趣的是:

1.HTML 5中的Canvas應用程序介面getImageData可以用來從驗證碼圖像中取得像素數據。利用Canvas,我們不僅可以將一個圖像嵌入一個畫布中,而且之後還可以再從中重新提取出來。

2.上述的腳本中包含一個完全使用JavaScript實現的神經網路。

3.使用Canvas從圖像中提取出像素數據後,將其送入神經網路,通過一種簡單的光學字元識別技術來推測驗證碼中到底使用了哪些字元。

通過閱讀源代碼,我們不僅可以更好地理解其工作原理,也可以領會這個驗證碼究竟是如何實現的。就像前面看到的那樣,這里使用的驗證碼不是很復雜——每個驗證碼有三個字元組成,每個字元使用一種不同的顏色,並且只使用26個字母中的字元,而所有字元都使用同一種字體。

⑸ 如何製作 java web 驗證碼

java web的驗證碼原理如下: 根據參數隨機生成一個字元串,將字元串存儲在一個靜態變數中,然後將字元串寫在圖片上傳遞到前台供用戶識別。用戶將識別出的字元串再提交到伺服器, 伺服器取出靜態變數中的字元串與之對比。然後將對比結果返回給用戶。
可以自己在網上找些實現好的代碼學習一下,也可以使用一些比較成熟的驗證碼組件。
隨著越來越發達的網路技術, 驗證碼技術也在不斷進步,有的驗證碼中的字元變成了中文,有的在圖片中生成問題來讓用戶回答,有的甚至用到了圖片歸類,但原理沒變。

⑹ javaweb,郵箱發送驗證碼後進行校驗。

簡單點,就是保存在緩存裡面,new一個map放在裡面就是了。校驗的話直接和map裡面的去比。

publicclassaaa{
publicstaticMap<String,String>map=newHashMap<String,String>();//定義一個靜態map,放驗證碼

//比如這個是生成驗證碼
publicStringCreateCheckCode(Stringname){
StringcheckCode="";
String[]arrs={"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"};
//隨機生成驗證碼、
for(inti=0;i<6;i++){
inta=(int)(Math.random()*28);
checkCode+=arrs[a];
}
//為了保證唯一性質,我們可以使用注冊的客戶的名字作為key
map.put(name,checkCode);
System.out.println(checkCode);
returncheckCode;
}
//這個可以作為控制層:比如客戶點擊驗證的連接,就會進入這個方法:來驗證驗證碼
publicbooleanverifyCheckCode(Stringname,StringcheckCode)
{
booleanflag=false;
Stringcode=map.get(name);
if(null!=code&&code.equals(checkCode)){
flag=true;
}

returnflag;

}


}

⑺ 如何用html編寫產生驗證碼

<HTML>
<HEAD>
<TITLE>生成驗證碼</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function createCode(len)
{
var seed = new Array(
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'0123456789'
); //創建需要的數據數組
var idx,i;
var result = ''; //返回的結果變數
for (i=0; i<len; i++) //根據指定的長度
{
idx = Math.floor(Math.random()*3); //獲得隨機數據的整數部分-獲取一個隨機整數
result += seed[idx].substr(Math.floor(Math.random()*(seed[idx].length)), 1);//根據隨機數獲取數據中一個值
}
return result; //返回隨機結果
}

function test() {
var inputRandom=document.getElementById("inputRandom").value;
var autoRandom=document.getElementById("autoRandom").innerHTML;
if(inputRandom==autoRandom) {
alert("通過驗證");
} else {
alert("沒有通過驗證");
}

}
</SCRIPT>
</HEAD>
<BODY>
驗證碼長度:
<SELECT id="sel">
<option value=1>1</option>
<option value=3>3</option>
<option value=5>5</option>
<option value=7 selected>7</option>
<option value=9>9</option>
</SELECT>
<BR>
<table>
<tr>
<td>驗證碼:</td>
<td><input type="text" id="inputRandom"></td>
<td><label id="autoRandom" value=""></label><INPUT TYPE="button" VALUE="獲取驗證碼" ONCLICK="autoRandom.innerHTML=createCode(sel.value)"></td>
<td><input type="button" value="驗證" onclick="test()"></td>
</tr>

</table>
<script type="text/javascript">
window.onload()=autoRandom.innerHTML=createCode(sel.value);
</script>
</BODY>
</HTML>

⑻ 怎麼在web登錄界面實現驗證碼功能

兩套方案
第一:使用標簽或者textbox(需設為只讀)輸出驗證碼
第二:讓驗證碼生成圖片,並加入隨機線條
思路在上面,具體方法網路一下 ^_^
goodluck!

⑼ web前端怎麼開發簡訊驗證功能

用戶點擊獲取驗證碼時,發送手機號到後端介面
後端接收請求後,將手機號及驗證碼發給簡訊網關,並將手機號和簡訊驗證碼保存起來
用戶收到簡訊後,輸入驗證碼,然後將驗證碼和手機號傳給後端
後端校驗手機號和驗證碼是否與之前保存的一致,如果一致,則鑒權通過
向前端發送認證通過的cookie以及通過狀態
前端進行頁面跳轉或其他業務邏輯

⑽ javaweb的驗證碼問題

點擊後,src屬性地址換一下,後面帶個時間戳欄位,這樣就不會緩存