📄 codegen.asp
字号:
<%
'------------------如意验证码产生类-------------------
'
'注意:您可以随意复制或传播以下代码,但请您保留此信息
' 您的支持,会让我们做得更好,谢谢:)
'
' 使用中有什么问题,欢迎来我们主页进行讨论
'
' 如易网络工作室
' http://www.royee.com
'
'-----------------------------------------------------
class CodeGen
public BgMap
public Font
public FontColor
public FontSize
public Width
public Height
public BgColor
public IsHaveFrame
public FrameColor
public FrameSize
public IsHaveNoisePoint
public IsHaveNoiseLine
public NoisePointNumber
public NoiseLineNumber
public NoisePointSize
public NoiseLineSize
public SessionKey
private data
private jpeg
private sub Class_Initialize()
set jpeg=server.CreateObject("Persits.Jpeg")
BgMap=""
BgColor=&HFFFFFF
FontColor=&H000000
Font="宋体"
FontSize=18
Width=80
Height=30
FrameColor=&H000000
FrameSize=1
IsHaveFrame=false
IsHaveNoisePoint=true
IsHaveNoiseLine=true
NoisePointNumber=100
NoiseLineNumber=20
NoisePointSize=2
NoiseLineSize=1
SessionKey="yzmm"
end sub
private sub setJpeg()
jpeg.Canvas.Font.Color = FontColor
jpeg.Canvas.Font.Family = Font
jpeg.Canvas.Font.Size = FontSize
jpeg.Canvas.Font.Bold = true
jpeg.Quality = 100
end sub
public function NumberGen(bit)
randomize()
str=""
for i=1 to bit
str=str&int(rnd()*10)
next
NumberGen=str
end function
public function AlphaGen(bit)
randomize()
str=""
i=1
while i<=bit
temp=(int(rnd()*(asc("z")-asc("A")))+asc("A"))
if (temp>=asc("A") and temp<=asc("Z")) or (temp>=asc("a") and temp<=asc("z")) then
str=str&chr(temp)
i=i+1
end if
wend
AlphaGen=str
end function
public function NumberAlphaGen(bit)
randomize()
str=""
i=1
while i<=bit
temp=(int(rnd()*(asc("z")-asc("0")))+asc("0"))
if (temp>=asc("A") and temp<=asc("Z")) or (temp>=asc("a") and temp<=asc("z")) or (temp>=asc("0") and temp<=asc("9")) then
str=str&chr(temp)
i=i+1
end if
wend
NumberAlphaGen=str
end function
public function CharacterGen(bit)
arrBase=array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f")
randomize ()
str=""
for i=1 to bit
r1=11+int(rnd()*3)
if r1=13 then
r2=int(rnd()*7)
else
r2=int(rnd()*16)
end if
r3=10+int(rnd()*6)
if r3=10 then
r4=1+int(rnd()*15)
elseif r3=15 then
r4=int(rnd()*15)
else
r4=int(rnd()*16)
end if
str=str&chr("&H"&arrBase(r1)&arrBase(r2)&arrBase(r3)&arrBase(r4))
next
CharacterGen=str
end function
public function UserTypeGen(bit,arrData)
str=""
if isarray(arrData) then
randomize()
for i=1 to bit
str=str&arrData(int(rnd()*(ubound(arrData)+1)))
next
end if
UserTypeGen=str
end function
public function StrGen(bit,genType,arrData)
select case ucase(genType)
case "N" '随机数字类型
StrGen=NumberGen(bit)
case "A"
StrGen=AlphaGen(bit) '随机字母类型
case "NA"
StrGen=NumberAlphaGen(bit) '随机数字字母混合类型
case "C"
StrGen=CharacterGen(bit) '随机汉字类型
case "U"
StrGen=UserTypeGen(bit,arrData) '随机用户自定义类型
case else
StrGen=""
end select
end function
public default function CodeGen(bit,genType,arrData)
response.buffer=true
response.Expires = -1
response.ContentType = "image/JPEG"
setJpeg()
dim fso
set fso=Server.CreateObject("Scripting.FileSystemObject")
if BgMap<>"" then
if fso.FileExists(server.MapPath(BgMap)) then
temp=true
else
temp=false
end if
else
temp=false
end if
if temp then
jpeg.open server.MapPath(BgMap)
else
jpeg.new Width,Height,BgColor
end if
if IsHaveFrame then
jpeg.Canvas.Pen.Color=FrameColor
jpeg.Canvas.Pen.Width=FrameSize
jpeg.Canvas.Brush.Solid=False
jpeg.Canvas.DrawBar 0,0,jpeg.width,jpeg.height
end if
if IsHaveNoiseLine then
randomize()
temp=int(NoiseLineNumber/10000*jpeg.width*jpeg.height)
jpeg.Canvas.Pen.Width=NoiseLineSize
for i=1 to temp
x1=int(rnd()*(jpeg.width+1))
y1=int(rnd()*(jpeg.height+1))
x2=int(rnd()*(jpeg.width+1))
y2=int(rnd()*(jpeg.height+1))
color=int(rnd()*(&H1000000))
jpeg.Canvas.Pen.Color=color
jpeg.Canvas.DrawLine x1,y1,x2,y2
next
end if
str= StrGen(bit,genType,arrData)
jpeg.Canvas.PrintText 8, int((jpeg.Height-16)/2),str
session(SessionKey)=str
if IsHaveNoisePoint then
randomize()
temp=int(NoisePointNumber/1000*jpeg.width*jpeg.height)
jpeg.Canvas.Pen.Width=NoisePointSize
for i=1 to temp
x=int(rnd()*(jpeg.width+1))
y=int(rnd()*(jpeg.height+1))
color=int(rnd()*(&H1000000))
jpeg.Canvas.Pen.Color=color
jpeg.Canvas.DrawLine x,y,x,y
next
end if
set fso=nothing
response.BinaryWrite jpeg.Binary
set jpeg=nothing
end function
end class
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -