随着自动注册、自动发布软件的越来越多,屏蔽自动注册发布垃圾消息是我们都会面临的问题,单纯的数字验证码已经不足以安全了,中文验证码就相对安全的多了。
ASP用aspjpeg组件生成中文验证码的方法
Response.Expires = -9999
response.addheader "pragma", "no-cache"
response.addheader "cache-ctrol", "no-cache"
Response.ContentType = "image/jpeg"
function make_randomize(max_len,w_n)'生成长度,w_n:0 可能包含字母,1:只为数字
randomize
txt="妈妈说我长大了要考清华上北大" '中文/数字/字母/ 最少4个
'response.write
make_randomize=Mid(txt,Rnd*(Len(txt)-max_len)+1,max_len)
end function
'=========================================
random_num=make_randomize(4,1) '生成4位的安全码
randomize
Session("GetCode")=random_num
Set Jpeg = Server.CreateObject("Persits.Jpeg") '调用组件
Jpeg.Open Server.MapPath("code.jpg") '打开准备的图片
Jpeg.Canvas.Font.Rotation = (Rnd*40-20) '倾斜度
Jpeg.Canvas.Font.Color = (Rnd*255)*255*255+255*255+(Rnd*255) '颜色
Jpeg.Canvas.Font.Family = "黑体" '字体 宋体/黑体/楷体/隶书/
Jpeg.Canvas.Font.Bold = true '是否加骈 true/false
Jpeg.Canvas.Font.Size = 16 '字体大小
Jpeg.Canvas.PrintText 2, 0, Mid(random_num,1,1) '添加位置,是生成水印的位置,建议不要休息
Jpeg.Canvas.Font.Rotation = (Rnd*40-20)
Jpeg.Canvas.Font.Color = (Rnd*255)*255*255+255*255+(Rnd*255)
Jpeg.Canvas.Font.Family = "宋体"
Jpeg.Canvas.Font.Bold = false
Jpeg.Canvas.Font.Size = 14
Jpeg.Canvas.PrintText 20, 0, Mid(random_num,2,1)
Jpeg.Canvas.Font.Rotation = (Rnd*40-20)
Jpeg.Canvas.Font.Color = (Rnd*255)*255*255+255*255+(Rnd*255)
Jpeg.Canvas.Font.Family = "楷体"
Jpeg.Canvas.Font.Bold = true
Jpeg.Canvas.Font.Size = 16
Jpeg.Canvas.PrintText 38, 0, Mid(random_num,3,1)
Jpeg.Canvas.Font.Rotation = (Rnd*40-20)
Jpeg.Canvas.Font.Color = (Rnd*255)*255*255+255*255+(Rnd*255)
Jpeg.Canvas.Font.Family = "隶书"
Jpeg.Canvas.Font.Bold = true
Jpeg.Canvas.Font.Size = 14
Jpeg.Canvas.PrintText 54, 0, Mid(random_num,4,1)