教程中国
PHOTOSHOP CS9.0中文版 MAYA 8.5 FOR WINDOWS Corel Painter v9.0 Flash MX2004 中文版 Illustrator cs2 中文版
VC++6.0含sp6 中英文版 VB6.0 +sp6 简体中文版 Borland Delphi 7汉化版 MSDN for vb6.0中文版 Visual Studio 2005简体
教程中国下属 文件存储共享专家BIBIDU.COM 提供大型软件,教材,源码,电影,音乐,图书等下载 更多精品请点此进入
  您目前所在位置: 教程中国 >> 编程基地 >> ASP >> ASP验证码的程序及原理(1) RSS订阅
ASP验证码的程序及原理(1)
教程(视频,书籍)下载:  ASP.NET AutoCAD 数据库 C# ASP java photoshop 网页设计 delphi 3dmax Flash C++ VB 张孝祥 实例   更多请进入BIBIDU搜索
IT搜索引擎   
一共4个页面:form.asp; chk.asp; num.asp; count.asp
得到一个随即数字。加密!
解密后成成XBM图片
利用session 判断

form.asp


<%
     '### To encrypt/decrypt include this code in your page
     '### strMyEncryptedString = EncryptString(strString)
     '### strMyDecryptedString = DeCryptString(strMyEncryptedString)
     '### You are free to use this code as long as credits remain in place
     '### also if you improve this code let me know.
     
     Private Function EncryptString(strString)
     '####################################################################
     '### Crypt Function (C) 2001 by Slavic Kozyuk grindkore@yahoo.com ###
     '### Arguments: strString <--- String you wish to encrypt ###
     '### Output: Encrypted HEX string ###
     '####################################################################
     
     Dim CharHexSet, intStringLen, strTemp, strRAW, i, intKey, intOffSet
     Randomize Timer
     
     intKey = Round((RND * 1000000) + 1000000) '##### Key Bitsize
     intOffSet = Round((RND * 1000000) + 1000000) '##### KeyOffSet Bitsize
     
     If IsNull(strString) = False Then
     strRAW = strString
     intStringLen = Len(strRAW)
     
     For i = 0 to intStringLen - 1
     strTemp = Left(strRAW, 1)
     strRAW = Right(strRAW, Len(strRAW) - 1)
     CharHexSet = CharHexSet & Hex(Asc(strTemp) * intKey)& Hex(intKey)
     Next
     
     EncryptString = CharHexSet & "|" & Hex(intOffSet + intKey) & "|" & Hex(intOffSet)
     Else
     EncryptString = ""
     End If
     End Function
     
     
     
     
     Private Function DeCryptString(strCryptString)
     '####################################################################
     '### Crypt Function (C) 2001 by Slavic Kozyuk grindkore@yahoo.com ###
     '### Arguments: Encrypted HEX stringt ###
     '### Output: Decrypted ASCII string ###
     '####################################################################
     '### Note this function uses HexConv() and get_hxno() functions ###
     '### so make sure they are not removed ###
     '####################################################################
     
     Dim strRAW, arHexCharSet, i, intKey, intOffSet, strRawKey, strHexCrypData
     
     
     strRawKey = Right(strCryptString, Len(strCryptString) - InStr(strCryptString, "|"))
     intOffSet = Right(strRawKey, Len(strRawKey) - InStr(strRawKey,"|"))
     intKey = HexConv(Left(strRawKey, InStr(strRawKey, "|") - 1)) - HexConv(intOffSet)
     strHexCrypData = Left(strCryptString, Len(strCryptString) - (Len(strRawKey) + 1))
     
     
     arHexCharSet = Split(strHexCrypData, Hex(intKey))
     
     For i=0 to UBound(arHexCharSet)
     strRAW = strRAW & Chr(HexConv(arHexCharSet(i))/intKey)
     Next
     
     DeCryptString = strRAW
     End Function
     
     
     
     Private Function HexConv(hexVar)
     Dim hxx, hxx_var, multiply
     IF hexVar <> "" THEN
     hexVar = UCASE(hexVar)
     hexVar = StrReverse(hexVar)
     DIM hx()
     REDIM hx(LEN(hexVar))
     hxx = 0
     hxx_var = 0
     FOR hxx = 1 TO LEN(hexVar)
     IF multiply = "" THEN multiply = 1
     hx(hxx) = mid(hexVar,hxx,1)
     hxx_var = (get_hxno(hx(hxx)) * multiply) + hxx_var
     multiply = (multiply * 16)
     NEXT
     hexVar = hxx_var
     HexConv = hexVar
     END IF
     End Function
     
     Private Function get_hxno(ghx)
     If ghx = "A" Then
     ghx = 10
     ElseIf ghx = "B" Then
     ghx = 11
     ElseIf ghx = "C" Then
     ghx = 12
     ElseIf ghx = "D" Then
     ghx = 13
     ElseIf ghx = "E" Then
     ghx = 14
     ElseIf ghx = "F" Then
     ghx = 15
     End If
     get_hxno = ghx
     End Function
     
     
     %>


<%
randomize
num = int(7999*rnd+2000) '计数器的值
num2 = EncryptString(num)
session("pwdt")=num
%>
<form action="chk.asp" method=post>
请输入验证码: <input type="text" name="pwds">
<img src="count.asp?sksid=<%=num2%>"> <input type=submit value=提交>
</form>


chk.asp
<%
if trim(request.form("pwds"))<>trim(session("pwdt")) then
%>
输入错误: 应该为:<%=session("pwdt")%>,可你输入的是:<%=request.form("pwds")%>
<%
else
%>
输入正确
<%end if%>

 

来源:upschool.cn
作者:
关键字:ASP验证码,程序,原理
发表日期:2006-10-7

网页显示有限 阅读全文请下载本文完整版WORD文档

上一篇:ASP验证码的程序及原理(2)   下一篇:ASP同一个帐号不能同时登陆的问题(2)


2009-1-8 22:27:45
本文的相类似文章
  • 在VB中操纵OLE服务器应用程序
  • 用VB编写键盘拦截程序
  • VB下如何编写CRC校验程序
  • VB编写入侵监听程序
  • COM程序编写入门(全文-1)
  • Delphi開發國際化應用程序
  • TListView在XP中的补丁程序
  • 利用VB6.0设计屏幕保护程序
  • 已知外部程序的hWnd,获取它的完整路径
  • 程序只运行一个实例,并且把前一个激活
  • 在学习中进步 在进步中成长 教程中国相随您的成长之路
    华腾联合科技股份有限公司版权所有
    广告联系:Rosibo@163.com