作者:绿色风
分类:
时间:2022-08-17
浏览:146
楼主 amulee |
Q:如何制作带有图片验证码的登陆窗口? A:生成验证码的主程序如下。可以生成随机的噪点,和一些网站验证系统原理相同。
- Type RndPic
- RndNumber As String
- FileName As String
- End Type
- Function Num2Arr(ByVal number As Long)
- Dim strNum As String
- Dim ArrTemp(3) As Byte
- '文件大小
- strNum = WorksheetFunction.Dec2Hex(number, 8)
- '数组转换
- For i = 0 To 3
- ArrTemp(i) = WorksheetFunction.Hex2Dec(Mid(strNum, i * 2 + 1, 2))
- Next i
- Num2Arr = ArrTemp
- End Function
- Function Create24BitCombinedNumber_RndColor(ByVal RndLen As Integer) As RndPic
- Dim Header(1 To 54) As Byte
- Dim FName As String
- Dim ArrColor(2) As Byte
- Dim ArrNumber(9) As String
- Dim arrRnd() As Integer
- Dim strLen As String
- Dim strRnd As String
- Dim LenTemp
- Dim WidthTemp
- Dim i%, j%, k%
- '生成随机数
- ReDim arrRnd(1 To RndLen)
- Randomize
- For i = 1 To RndLen
- arrRnd(i) = Int(Rnd * 10)
- strRnd = strRnd & arrRnd(i)
- Next i
- '文件大小
- LenTemp = Num2Arr(RndLen * 300 + 54)
- WidthTemp = Num2Arr(RndLen * 12)
- '定义数字数组
- ArrNumber(0) = "111111111111111100001111111011110111111011110111111011110111111011110111111011110111111011110111111011110111111011110111111100001111111111111111"
- ArrNumber(1) = "111111111111111110111111111000111111111110111111111110111111111110111111111110111111111110111111111110111111111110111111111000001111111111111111"
- ArrNumber(2) = "111111111111111100001111111011110111111011110111111111110111111111101111111111011111111110111111111101111111111011110111111000000111111111111111"
- ArrNumber(3) = "111111111111111100001111111011110111111011110111111111101111111110011111111111101111111111110111111011110111111011110111111100001111111111111111"
- ArrNumber(4) = "111111111111111111011111111111011111111110011111111101011111111011011111111011011111111000000111111111011111111111011111111110000111111111111111"
- ArrNumber(5) = "111111111111111000000111111011111111111011111111111010001111111001110111111111110111111111110111111011110111111011110111111100001111111111111111"
- ArrNumber(6) = "1111111111111111100011111111011101111110111111111110111111111110100011111110011101111110111101111110111101111110111101111111000011111111111111111"
- ArrNumber(7) = "111111111111111000000111111011101111111011101111111111011111111111011111111110111111111110111111111110111111111110111111111110111111111111111111"
- ArrNumber(8) = "111111111111111100001111111011110111111011110111111011110111111100001111111101101111111011110111111011110111111011110111111100001111111111111111"
- ArrNumber(9) = "111111111111111100011111111011101111111011110111111011110111111011100111111100010111111111110111111111110111111011101111111100011111111111111111"
- '文件头
- Header(1) = 66
- Header(2) = 77
- Header(3) = LenTemp(3)
- Header(4) = LenTemp(2)
- Header(5) = LenTemp(1)
- Header(6) = LenTemp(0)
- Header(11) = 54
- Header(15) = 40
- Header(19) = WidthTemp(3)
- Header(20) = WidthTemp(2)
- Header(21) = WidthTemp(1)
- Header(22) = WidthTemp(0)
- Header(23) = 12
- Header(27) = 1
- Header(29) = 24
- Header(39) = 18
- Header(40) = 11
- Header(43) = 18
- Header(44) = 11
- '开始生成文件
- FName = ThisWorkbook.Path & "\" & RndLen & "位随机数.bmp"
- FS = FreeFile
- Open FName For Binary Access Write As #FS
- '写文件头
- Put #FS, , Header
- '写颜色
- Pos = 55
- For i = 11 To 0 Step -1 '行
- For k = 1 To RndLen '数字
- For j = 1 To 12 '写12个像素
- Randomize
- If Mid(ArrNumber(arrRnd(k)), i * 12 + j, 1) = "0" Then
- ArrColor(0) = Abs(Rnd * 256 - 128)
- ArrColor(1) = Abs(Rnd * 256 - 128)
- ArrColor(2) = Abs(Rnd * 256 - 128)
- Else
- ArrColor(0) = Rnd * 80 + 170
- ArrColor(1) = Rnd * 80 + 170
- ArrColor(2) = Rnd * 80 + 170
- End If
- Put #FS, Pos, ArrColor
- Pos = Pos + 3
- Next j
- Next k
- Next i
- Close #FS
- Create24BitCombinedNumber_RndColor.FileName = FName
- Create24BitCombinedNumber_RndColor.RndNumber = strRnd
- End Function
效果如图:
附件下载: 验证码登陆.rar |
2楼 ljh29206 |
- -!! 你也太猛了吧 版主! 强悍,.,........ |
3楼 ljh29206 |
我在 测试的时候 直接 就在
userform1.show 哪里就报错,
好像没什么错吧,请指点下!
另外 ArrNumber(0) = "111111111111111100001111111011110111111011110111111011110111111011110111111011110111111011110111111011110111111011110111111100001111111111111111" ArrNumber(1) = "111111111111111110111111111000111111111110111111111110111111111110111111111110111111111110111111111110111111111110111111111000001111111111111111" ArrNumber(2) = "111111111111111100001111111011110111111011110111111111110111111111101111111111011111111110111111111101111111111011110111111000000111111111111111" ArrNumber(3) = "111111111111111100001111111011110111111011110111111111101111111110011111111111101111111111110111111011110111111011110111111100001111111111111111" ArrNumber(4) = "111111111111111111011111111111011111111110011111111101011111111011011111111011011111111000000111111111011111111111011111111110000111111111111111" ArrNumber(5) = "111111111111111000000111111011111111111011111111111010001111111001110111111111110111111111110111111011110111111011110111111100001111111111111111" ArrNumber(6) = "1111111111111111100011111111011101111110111111111110111111111110100011111110011101111110111101111110111101111110111101111111000011111111111111111" ArrNumber(7) = "111111111111111000000111111011101111111011101111111111011111111111011111111110111111111110111111111110111111111110111111111110111111111111111111" ArrNumber(8) = "111111111111111100001111111011110111111011110111111011110111111100001111111101101111111011110111111011110111111011110111111100001111111111111111" ArrNumber(9) = "111111111111111100011111111011101111111011110111111011110111111011100111111100010111111111110111111111110111111011101111111100011111111111111111"
这段东西的定义是什么,,,, |
4楼 amulee |
这些数字就是数字的点阵图 这样看明白些吧。
|
5楼 ljh29206 |
原来这样! 收藏了 |
6楼 wqfzqgk |
|
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一