ASP產生彩色可變長驗證碼程式

來源:互聯網
上載者:User
程式|驗證碼   記得“想當年”某天上午在這裡路過,看到一位朋友貼的自己寫的驗證碼程式,雖然他的程式是黑白有雜點,但其實很容易被破解的,但卻有不少人喜歡著。。。沒辦法,當天下午研究了一翻 BMP 圖片,然後就寫出了這些代碼,只是當初沒有公布,眼看今天這麼多壞人亂在很多論壇上註冊使用者來發廣告,所以才貼出來共用一下。

  本驗證碼產生程式特點如下:

  一、彩色;

  二、BMP 映像色深為 16 位,產生的圖片體積更小;(4位長的驗證碼只有幾百位元組)

  三、長度可自訂;(1位至25位可固定設定,也可以自己改成動態)

  四、背景雜色深度可自訂;

  具體請看代碼

  註:代碼中並沒有針對動網的 設定驗證碼 Session 的地方。想用的朋友自己根據需要改一下,位置就在代碼中出現 Session("Num") 的那一行,改成自己需要的名稱就可以了。這個驗證碼也可以用在任何需要驗證碼的地方。不用在動網論壇也可。

  下面是代碼部分:
<--r>Option Explicit
Response.Expires = 0
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
Response.ContentType = "Image/BMP"
Randomize Timer

Dim Text_Data(9),Text_Len,Int_Temp(),I,j,k,Int_Temp2

''***** 參數配置區 *****

Text_Len = 4 ''驗證碼長度(支援1-25位)

''**********************

ReDim Int_Temp( Text_Len - 1 )

Text_Data(0) = "00000000000001111000001100110000110111000011011100001100110000111011000011101100001100110000011110000000000000"
Text_Data(1) = "00000000000000011000000011100000111110000000011000000001100000000110000000011000000001100000000110000000000000"
Text_Data(2) = "00000000000001111000001100110000110011000000001100000001100000001100000001100000001100000000111111000000000000"
Text_Data(3) = "00000000000001111000001100110000110011000000001100000011100000000011000011001100001100110000011110000000000000"
Text_Data(4) = "00000000000001100000000110000000011011000001101100000110110000110011000011111110000000110000000011000000000000"
Text_Data(5) = "00000000000011111100001100000000110000000011000000001111100000000011000000001100000001100000111100000000000000"
Text_Data(6) = "00000000000000111000000011000000011000000011111000001100110000110011000011001100001100110000011110000000000000"
Text_Data(7) = "00000000000011111100000000110000000110000000011000000011000000001100000001100000000110000000011000000000000000"
Text_Data(8) = "00000000000001111000001100110000110011000011101100000111100000110111000011001100001100110000011110000000000000"
Text_Data(9) = "00000000000001111000001100110000110011000011001100001100110000011111000000011000000011000000011100000000000000"

''下面隨機產生各位驗證碼
Session("Num") = ""
For I = 0 To Text_Len - 1
Int_Temp(I) = Int(Rnd * 10)
Session("Num") = Session("Num") + Mid("0123456789",Int_Temp(I)+1,1)
Next

''下面輸出檔案頭部分
Int_Temp2 = (Text_Len - 1) \ 4 * 220 + ((Text_Len - 1) / 4 - (Text_Len - 1) \ 4 * 4) * 44
Response.BinaryWrite ChrB(&H42) & ChrB(&H4D)
Response.BinaryWrite ChrB(((Int_Temp2 + 206) / 256 - (Int_Temp2 + 206) \ 256) * 256) & ChrB((Int_Temp2 + 206) \ 256) ''特殊位
Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&H76) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&H28) & ChrB(0) & ChrB(0) & ChrB(0)
Response.BinaryWrite ChrB(Text_Len * 10) ''特殊位
Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&HB) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&H1) & ChrB(0) & ChrB(&H4) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)
Response.BinaryWrite ChrB(((Int_Temp2 + 88) / 256 - (Int_Temp2 + 88) \ 256) * 256) & ChrB((Int_Temp2 + 88) \ 256) ''特殊位

Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(16) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(16) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&H80) & ChrB(0) & ChrB(0) & ChrB(&H80) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&H80) & ChrB(&H80) & ChrB(0) & ChrB(&H80) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&H80) & ChrB(0) & ChrB(&H80) & ChrB(0)
Response.BinaryWrite ChrB(&H80) & ChrB(&H80) & ChrB(0) & ChrB(0) & ChrB(&H80) & ChrB(&H80) & ChrB(&H80) & ChrB(0) & ChrB(&HC0) & ChrB(&HC0) & ChrB(&HC0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&HFF) & ChrB(0) & ChrB(0) & ChrB(&HFF) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&HFF) & ChrB(&HFF) & ChrB(0) & ChrB(&HFF) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&HFF) & ChrB(0) & ChrB(&HFF) & ChrB(0) & ChrB(&HFF) & ChrB(&HFF) & ChrB(0) & ChrB(0) & ChrB(&HFF) & ChrB(&HFF) & ChrB(&HFF) & ChrB(0)

''下面輸出圖片資料
For i = 10 to 0 Step -1
For j = 0 to Text_Len - 1
For k = 1 to 9 Step 2
If Mid(Text_Data(Int_Temp(j)) , i * 10 + k , 1) = "0" Then Int_Temp2 = Get_BackColor() * 16 Else Int_Temp2 = Get_ForeColor() * 16
If Mid(Text_Data(Int_Temp(j)) , i * 10 + k + 1 , 1) = "0" Then Int_Temp2 = Int_Temp2 + Get_BackColor() Else Int_Temp2 = Int_Temp2 + Get_ForeColor()
Response.BinaryWrite ChrB(Int_Temp2)
Next
Next
Int_Temp2 = (Text_Len / 4 - Text_Len \ 4) * 4
Select Case Int_Temp2
Case 1
Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0)
Case 2
Response.BinaryWrite ChrB(0) & ChrB(0)
Case 3
Response.BinaryWrite ChrB(0)
End Select
Next

Function Get_BackColor()
''得到一個背景色
If Int(Rnd * 30) = 0 Then ''註:此處的 Rnd * 30 是決定背景雜色的多少,值越大,則雜色越少,圖片越容易看清楚
Get_BackColor = CInt(Mid("00021209",Int(Rnd * 4) * 2 + 1,2))
Else
Get_BackColor = CInt(Mid("081515151515",Int(Rnd * 6) * 2 + 1,2))
End If
End Function

Function Get_ForeColor()
''得到一個前景色彩
Get_ForeColor = CInt(Mid("00021209",Int(Rnd * 4) * 2 + 1,2))
End Function

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.