第三篇: asp程序与discuz v4.10的整合方法
1.文件discuz_passport.asp
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 c255 Then
t=t+1
End If
Next
strLength=t
Else
strLength=len(str)
End If
If err.number0 Then err.clear
End Function
%>
2.文件 login.asp
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") & " 你好 你已登陆成功" &_
" [url=]点击这里退出登陆[/url]" &_
" [url=]点击这里访问论坛[/url]
"
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 为
[color=]abc@hotmail.com
// c# dz通行证解码函数
public string passport_decrypt(string txt, string key){
byte[] t = Convert.FromBase64String(txt);
byte[] btxt = passport_key(t, key);
byte[] btmp = new byte[btxt.Length];
int j = 0;
for (int i = 0; i
// c# dz通行证密匙处理函数
public byte[] passport_key(byte[] btxt, string key){
key = md5(key);
byte[] keyAry = strToByteAry(key);
int ctr = 0;
byte[] tmp = new byte[btxt.Length];
for (int i = 0; i
// md5加密
public string md5(string str){
MD5 md5Hasher = MD5.Create();
string re="";
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(str));
for (int i = 0; i