• 3359阅读
  • 0回复

asp彩色随机码的生成 [复制链接]

上一主题 下一主题
离线cai
 

只看楼主 倒序阅读 0楼 发表于: 2005-09-26
代码:

  1. <%
  2. Option Explicit
  3. Response.Expires = 0
  4. Response.AddHeader "Pragma","no-cache"
  5. Response.AddHeader "cache-ctrol","no-cache"
  6. Response.ContentType = "Image/BMP"
  7. Randomize Timer
  8. Dim Text_Data(9),Text_Len,Int_Temp(),I,j,k,Int_Temp2
  9. ''***** 参数配置区 *****
  10. Text_Len = 4 ''验证码长度(支持1-25位)
  11. ''**********************
  12. ReDim Int_Temp( Text_Len - 1 )
  13. Text_Data(0) = "00000000000001111000001100110000110111000011011100001100110000111011000011101100001100110000011110000000000000"
  14. Text_Data(1) = "00000000000000011000000011100000111110000000011000000001100000000110000000011000000001100000000110000000000000"
  15. Text_Data(2) = "00000000000001111000001100110000110011000000001100000001100000001100000001100000001100000000111111000000000000"
  16. Text_Data(3) = "00000000000001111000001100110000110011000000001100000011100000000011000011001100001100110000011110000000000000"
  17. Text_Data(4) = "00000000000001100000000110000000011011000001101100000110110000110011000011111110000000110000000011000000000000"
  18. Text_Data(5) = "00000000000011111100001100000000110000000011000000001111100000000011000000001100000001100000111100000000000000"
  19. Text_Data(6) = "00000000000000111000000011000000011000000011111000001100110000110011000011001100001100110000011110000000000000"
  20. Text_Data(7) = "00000000000011111100000000110000000110000000011000000011000000001100000001100000000110000000011000000000000000"
  21. Text_Data(8) = "00000000000001111000001100110000110011000011101100000111100000110111000011001100001100110000011110000000000000"
  22. Text_Data(9) = "00000000000001111000001100110000110011000011001100001100110000011111000000011000000011000000011100000000000000"
  23. ''下面随机生成各位验证码
  24. Session("Num") = ""
  25. For I = 0 To Text_Len - 1
  26.   Int_Temp(I) = Int(Rnd * 10)
  27.   Session("Num") = Session("Num") + Mid("0123456789",Int_Temp(I)+1,1)
  28. Next
  29. ''下面输出文件头部分
  30. Int_Temp2 = (Text_Len - 1) \ 4 * 220 + ((Text_Len - 1) / 4 - (Text_Len - 1) \ 4 * 4) * 44
  31. Response.BinaryWrite ChrB(&H42) & ChrB(&H4D)
  32. Response.BinaryWrite ChrB(((Int_Temp2 + 206) / 256 - (Int_Temp2 + 206) \ 256) * 256) & ChrB((Int_Temp2 + 206) \ 256)   ''特殊位
  33. 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)
  34. Response.BinaryWrite ChrB(Text_Len * 10)   ''特殊位
  35. 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)
  36. Response.BinaryWrite ChrB(((Int_Temp2 + 88) / 256 - (Int_Temp2 + 88) \ 256) * 256) & ChrB((Int_Temp2 + 88) \ 256)   ''特殊位
  37. 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)
  38. 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)
  39. ''下面输出图片数据
  40. For i = 10 to 0 Step -1
  41.   For j = 0 to Text_Len - 1
  42.     For k = 1 to 9 Step 2
  43.       If Mid(Text_Data(Int_Temp(j)) , i * 10 + k , 1) = "0" Then Int_Temp2 = Get_BackColor() * 16 Else Int_Temp2 = Get_ForeColor() * 16
  44.       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()
  45.       Response.BinaryWrite ChrB(Int_Temp2)
  46.     Next
  47.   Next
  48.   Int_Temp2 = (Text_Len / 4 - Text_Len \ 4) * 4
  49.   Select Case Int_Temp2
  50.   Case 1
  51.     Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0)
  52.   Case 2
  53.     Response.BinaryWrite ChrB(0) & ChrB(0)
  54.   Case 3
  55.     Response.BinaryWrite ChrB(0)
  56.   End Select
  57. Next
  58. Function Get_BackColor()
  59. ''得到一个背景色
  60. If Int(Rnd * 30) = 0 Then ''注:此处的 Rnd * 30 是决定背景杂色的多少,值越大,则杂色越少,图片越容易看清楚
  61.   Get_BackColor = CInt(Mid("00021209",Int(Rnd * 4) * 2 + 1,2))
  62. Else
  63.   Get_BackColor = CInt(Mid("081515151515",Int(Rnd * 6) * 2 + 1,2))
  64. End If
  65. End Function
  66. Function Get_ForeColor()
  67. ''得到一个前景色
  68. Get_ForeColor = CInt(Mid("00021209",Int(Rnd * 4) * 2 + 1,2))
  69. End Function
  70. %>


使用的时候:
使用 Session("Num") 比较
grant all privileges on *.* to 'a'@'localhost' identified by 'a' with grant option;flush privileges;
快速回复
限100 字节
 
上一个 下一个