本帖最后由 chigco 于 2009-11-6 23:42 编辑
你可以去参考官方的PassPort。
部分参考:
1.文件discuz_passport.asp
<%
'请保留以下信息以备出现问题时使用
'贡献者 huozhe3136 QQ:2666556
'=====================================================
'============仿discuz passport编码函数================
'=====================================================
function passport_encrypt(txt, key)
dim encrypt_key, encrypt_key_ary,txt_ary
dim ctr,tmp,i
Randomize
encrypt_key=md5(Int(32000* Rnd),32)
encrypt_key_ary=strtoary(encrypt_key)
txt_ary=strtoary(txt)
ctr = 0
tmp = ""
for i = 0 to StrLength(txt)-1
if ctr=len(encrypt_key) then ctr=0 else ctr=ctr
tmp = tmp & encrypt_key_Ary(ctr) & mxor(txt_ary(i),encrypt_key_ary(ctr))
ctr=ctr+1
next
passport_encrypt=strAnsi2Unicode(base64Encode(passport_key(tmp, key)))
end function
'=====================================================
'============仿discuz passport解码函数================
'=====================================================
function passport_decrypt(txt, key)
Dim txt_ary,tmp,i
txt = passport_key(base64Decode(strUnicode2Ansi(txt)), key)
txt_ary = AnsiToAry(txt)
' 变量初始化
tmp = ""
for i = 0 To lenb(txt)-1
tmp = tmp & mxor(txt_ary(i),txt_ary(i+1))
i=i+1
next
passport_decrypt = strAnsi2Unicode(tmp)
end function
'=====================================================
'==========仿discuz Passport 密匙处理函数=============
'=====================================================
function passport_key(ansitxt, encrypt_key)
dim encrypt_key_tmp,encrypt_key_ary,txt_ary
dim ctr,tmp,i
encrypt_key_tmp = md5(encrypt_key,32)
encrypt_key_ary=StrToAry(encrypt_key_tmp)
txt_ary=AnsiToAry(ansitxt)
ctr = 0
tmp = ""
for i=0 to lenb(ansitxt)-1
if ctr=len(encrypt_key_tmp) then ctr=0 else ctr=ctr
tmp= tmp & mxor(txt_ary(i),encrypt_key_ary(ctr))
ctr=ctr+1
next
passport_key=tmp
end function
'=====================================================
'=================将字符串转换为Ansi数组==============
'=====================================================
function StrToAry(str)
dim ary(),length,tmpstr,i
tmpstr=strUnicode2Ansi(str)
length=lenb(tmpstr)
redim ary(length)
for i=0 to length-1
ary(i)=midb(tmpstr,i+1,1)
next
StrToAry=ary
end function
'=====================================================
'=================将Ansi字符串转换为Ansi数组==========
'=====================================================
function AnsiToAry(str)
dim ary(),length,i
length=lenb(str)
redim ary(length)
for i=0 to length-1
ary(i)=midb(str,i+1,1)
next
AnsiToAry=ary
end function
'=====================================================
'=================异或操作============================
'=====================================================
function mxor(chrb1,chrb2)
if chrb1<>"" and chrb2 <>"" then
mxor=chrb(ascb(chrb1) xor ascb(chrb2))
end if
end function
Function StrLength(str)
ON ERROR RESUME NEXT
Dim WINNT_CHINESE
WINNT_CHINESE = (len("中国")=2)
If WINNT_CHINESE Then
Dim l,t,c
Dim i
l=len(str)
t=l
For i=1 To l
c=asc(mid(str,i,1))
If c<0 Then c=c+65536
If c>255 Then
t=t+1
End If
Next
strLength=t
Else
strLength=len(str)
End If
If err.number<>0 Then err.clear
End Function
%>
2.文件 login.asp
<!--#include file="md5.asp"-->
<!--#include file="base64.asp"-->
<!--#include file="discuz_passport.asp"-->
<%
'asp的整合方法已更新,,中文注册乱码问题已解决
'================================================================
'=====================用法示例==疑问加我QQ:2666556===============
'================================================================
dim PassportKey,YourAspWeb_Url,DiscuzBbs_Url
PassportKey="1234567890" '这里换成你discuz论坛通行证设置的passportkey
YourAspWeb_Url="http://localhost/test2/login.asp" '这里换成你的主页绝对地址或相对地址
DiscuzBbs_Url="http://localhost:8080/discuz/" '这里换成你的discuz论坛绝对地址或相对地址
select case request.QueryString("act")
case "login" call login()
case "logout" call logout()
end select
if request.Cookies("username")<>"" then
dim str
str=request.Cookies("username") & " 你好 你已登陆成功" &_
" <a href=""t3.asp?act=logout"">点击这里退出登陆</a>" &_
" <a href="""& DiscuzBbs_Url & """>点击这里访问论坛</a><br>"
response.Write(str)
end if
function logout()
dim auth,forward,verify
auth=request.Cookies("auth")
response.Cookies("username")=""
response.Cookies("auth")=""
forward=request.QueryString("forward")
if forward="" then forward=YourAspWeb_Url
verify = md5("logout"& auth & forward & PassportKey ,32)
auth=server.URLEncode(auth)
forward=server.URLEncode(forward)
response.Redirect(DiscuzBbs_Url & "api/passport.php?action=logout&auth=" & auth & "&forward=" & forward & "&verify=" & verify)
end function
function login()
dim auth,forward,verify,member_info
'需根据实际情况修改,这里只作最简单的验证
if request.Form("username")="admin" and request.Form("password")="123456" then
'设置自己的cookie 或 session
response.Cookies("username")=request.Form("username")
'========================================================
'===============passport 整合开始========================
'========================================================
'假设从用户数据库里取出email 为abc@hotmail.com
member_info="time=" & datediff("s","1970-1-1 00:00:00",now) &_
"&username=" & request.Form("username") &_
"&password=" & md5(request.Form("password"),32) &_
"&email=" & "abc@hotmail.com"
auth = passport_encrypt(member_info , PassportKey)
response.Cookies("auth")=auth
forward=request.form("forward")
if forward="" then forward=YourAspWeb_Url
verify = md5("login" & auth & forward & PassportKey,32)
auth=server.URLEncode(auth)
forward=server.URLEncode(forward)
response.Redirect(DiscuzBbs_Url & "api/passport.php?action=login&auth=" & auth & "&forward=" & forward & "&verify=" & verify)
'========================================================
'===============passport 整合结束========================
'========================================================
else
response.Write("登陆失败<br>")
end if
end function
%>
<form name="form1" method="post" action="login.asp?act=login">
用户名:
<input type="text" name="username">
<br>
密 码:
<input type="password" name="password">
<br>
<input type="hidden" name="forward" value="<%=request.QueryString("forward")%>">
<input type="submit" name="Submit" value=" 登 陆 ">
</form> |