?? 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 + -