分享
 
 
 

ASP程序无组件生成验证码

王朝asp·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

一、无组件生成验证码-GIF格式

<%

Option Explicit ' 显示声明

Class Com_GifCode_Class

'''''''''''''''''''''''''''''''''''''''''''''

' Author: Layen support@ssaw.net 84815733(QQ)

' Thanks: Laomi, Laomiao, NetRube

' 2006-01-02

'''''''''''''''''''''''''''''''''''''''''''''

Public Noisy, Count, Width, Height, Angle, Offset, Border

Private Graph(), Margin(3)

Private Sub Class_Initialize()

Randomize

Noisy = 16 ' 干扰点出现的概率

Count = 4 ' 字符数量

Width = 80 ' 图片宽度

Height = 20 ' 图片高度

Angle = 2 ' 角度随机变化量

Offset = 20 ' 偏移随机变化量

Border = 1 ' 边框大小

End Sub

Public Function Create()

Const cCharSet = "123456789"

Dim i, x, y

Dim vValidCode : vValidCode = ""

Dim vIndex

ReDim Graph(Width-1, Height-1)

For i = 0 To Count - 1

vIndex = Int(Rnd * Len(cCharSet))

vValidCode = vValidCode + Mid(cCharSet, vIndex+1 , 1)

SetDraw vIndex, i

Next

Create = vValidCode

End Function

Sub SetDot(pX, pY)

If pX * (Width-pX-1) >= 0 And pY * (Height-pY-1) >= 0 Then

Graph(pX, pY) = 1

End If

End Sub

Public Sub SetDraw(pIndex, pNumber)

' 字符数据

Dim DotData(8)

DotData(0) = Array(30, 15, 50, 1, 50, 100)

DotData(1) = Array(1 ,34 ,30 ,1 ,71, 1, 100, 34, 1, 100, 93, 100, 100, 86)

DotData(2) = Array(1, 1, 100, 1, 42, 42, 100, 70, 50, 100, 1, 70)

DotData(3) = Array(100, 73, 6, 73, 75, 6, 75, 100)

DotData(4) = Array(100, 1, 1, 1, 1, 50, 50, 35, 100, 55, 100, 80, 50, 100, 1, 95)

DotData(5) = Array(100, 20, 70, 1, 20, 1, 1, 30, 1, 80, 30, 100, 70, 100, 100, 80, 100, 60, 70, 50, 30, 50, 1, 60)

DotData(6) = Array(6, 26, 6, 6, 100, 6, 53, 100)

DotData(7) = Array(100, 30, 100, 20, 70, 1, 30, 1, 1, 20, 1, 30, 100, 70, 100, 80, 70, 100, 30, 100, 1, 80, 1, 70, 100, 30)

DotData(8) = Array(1, 80, 30, 100, 80, 100, 100, 70, 100, 20, 70, 1, 30, 1, 1, 20, 1, 40, 30, 50, 70, 50, 100, 40)

Dim vExtent : vExtent = Width / Count

Margin(0) = Border + vExtent * (Rnd * Offset) / 100 + Margin(1)

Margin(1) = vExtent * (pNumber + 1) - Border - vExtent * (Rnd * Offset) / 100

Margin(2) = Border + Height * (Rnd * Offset) / 100

Margin(3) = Height - Border - Height * (Rnd * Offset) / 100

Dim vStartX, vEndX, vStartY, vEndY

Dim vWidth, vHeight, vDX, vDY, vDeltaT

Dim vAngle, vLength

vWidth = Int(Margin(1) - Margin(0))

vHeight = Int(Margin(3) - Margin(2))

' 起始坐标

vStartX = Int((DotData(pIndex)(0)-1) * vWidth / 100)

vStartY = Int((DotData(pIndex)(1)-1) * vHeight / 100)

Dim i, j

For i = 1 To UBound(DotData(pIndex), 1)/2

If DotData(pIndex)(2*i-2) <> 0 And DotData(pIndex)(2*i) <> 0 Then

' 终点坐标

vEndX = (DotData(pIndex)(2*i)-1) * vWidth / 100

vEndY = (DotData(pIndex)(2*i+1)-1) * vHeight / 100

' 横向差距

vDX = vEndX - vStartX

' 纵向差距

vDY = vEndY - vStartY

' 倾斜角度

If vDX = 0 Then

vAngle = Sgn(vDY) * 3.14/2

Else

vAngle = Atn(vDY / vDX)

End If

' 两坐标距离

If Sin(vAngle) = 0 Then

vLength = vDX

Else

vLength = vDY / Sin(vAngle)

End If

' 随机转动角度

vAngle = vAngle + (Rnd - 0.5) * 2 * Angle * 3.14 * 2 / 100

vDX = Int(Cos(vAngle) * vLength)

vDY = Int(Sin(vAngle) * vLength)

If Abs(vDX) > Abs(vDY) Then vDeltaT = Abs(vDX) Else vDeltaT = Abs(vDY)

For j = 1 To vDeltaT

SetDot Margin(0) + vStartX + j * vDX / vDeltaT, Margin(2) + vStartY + j * vDY / vDeltaT

Next

vStartX = vStartX + vDX

vStartY = vStartY + vDY

End If

Next

End Sub

Public Sub Output()

Response.Expires = -9999

Response.AddHeader "pragma", "no-cache"

Response.AddHeader "cache-ctrol", "no-cache"

Response.ContentType = "image/gif"

' 文件类型

Response.BinaryWrite ChrB(Asc("G")) & ChrB(Asc("I")) & ChrB(Asc("F"))

' 版本信息

Response.BinaryWrite ChrB(Asc("8")) & ChrB(Asc("9")) & ChrB(Asc("a"))

' 逻辑屏幕宽度

Response.BinaryWrite ChrB(Width Mod 256) & ChrB((Width \ 256) Mod 256)

' 逻辑屏幕高度

Response.BinaryWrite ChrB(Height Mod 256) & ChrB((Height \ 256) Mod 256)

Response.BinaryWrite ChrB(128) & ChrB(0) & ChrB(0)

' 全局颜色列表

Response.BinaryWrite ChrB(255) & ChrB(255) & ChrB(255)

Response.BinaryWrite ChrB(0) & ChrB(85) & ChrB(255)

' 图象标识符

Response.BinaryWrite ChrB(Asc(","))

Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)

' 图象宽度

Response.BinaryWrite ChrB(Width Mod 256) & ChrB((Width \ 256) Mod 256)

' 图象高度

Response.BinaryWrite ChrB(Height Mod 256) & ChrB((Height \ 256) Mod 256)

Response.BinaryWrite ChrB(0) & ChrB(7) & ChrB(255)

Dim x, y, i : i = 0

For y = 0 To Height - 1

For x = 0 To Width - 1

If Rnd < Noisy / 100 Then

Response.BinaryWrite ChrB(1-Graph(x, y))

Else

If x * (x-Width) = 0 Or y * (y-Height) = 0 Then

Response.BinaryWrite ChrB(Graph(x, y))

Else

If Graph(x-1, y) = 1 Or Graph(x, y) Or Graph(x, y-1) = 1 Then

Response.BinaryWrite ChrB(1)

Else

Response.BinaryWrite ChrB(0)

End If

End If

End If

If (y * Width + x + 1) Mod 126 = 0 Then

Response.BinaryWrite ChrB(128)

i = i + 1

End If

If (y * Width + x + i + 1) Mod 255 = 0 Then

If (Width*Height - y * Width - x - 1) > 255 Then

Response.BinaryWrite ChrB(255)

Else

Response.BinaryWrite ChrB(Width * Height Mod 255)

End If

End If

Next

Next

Response.BinaryWrite ChrB(128) & ChrB(0) & ChrB(129) & ChrB(0) & ChrB(59)

End Sub

End Class

Dim mCode

Set mCode = New Com_GifCode_Class

Session("GetCode") = mCode.Create()

mCode.Output()

Set mCode = Nothing

%>

保存成ASP文件即可看见效果!

二、无组件生成验证码-BMP格式

Call Com_CreatValidCode("ValidCode")

Sub Com_CreatValidCode(pSN)

'Author: Layen

'QQ: 84815733

'E-mail: support@ssaw.net

' 禁止缓存

Response.Expires = -9999

Response.AddHeader "Pragma","no-cache"

Response.AddHeader "cache-ctrol","no-cache"

Response.ContentType = "Image/BMP"

Randomize

Dim i, ii, iii

Const cOdds = 8 ' 杂点出现的机率

Const cAmount = 36 ' 文字数量

Const cCode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

' 颜色的数据(字符,背景)

Dim vColorData(1)

vColorData(0) = ChrB(0) & ChrB(0) & ChrB(0) ' 蓝0,绿0,红0(黑色)

vColorData(1) = ChrB(250) & ChrB(236) & ChrB(211) ' 蓝250,绿236,红211(浅蓝色)

' 随机产生字符

Dim vCode(4), vCodes

For i = 0 To 3

vCode(i) = Int(Rnd * cAmount)

vCodes = vCodes & Mid(cCode, vCode(i) + 1, 1)

Next

Session(pSN) = vCodes '记录入Session

' 字符的数据

Dim vNumberData(35)

vNumberData(0) = "1110000111110111101111011110111101001011110100101111

010010111101001011110111101111011110111110000111"

vNumberData(1) = "1111011111110001111111110111111111011111111101111111

11011111111101111111110111111111011111110

[1] [2] [3] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有