高手请进

石牌桥网管 2003-01-16 08:45:44
我现在有两个站点:a.com 和 b.com
用户信息数据库(登录帐号、密码)全部在a.com上,a.com的用户信息数据对b.com是保密的
现在问题是怎么实现通过a.com上密码验证后才能进入b.com的后台管理?
b.com上后台管理需要很高的安全性

还问一个问题:
不知a.com上的session值能不能传到b.com上
...全文
77 37 打赏 收藏 转发到动态 举报
写回复
用AI写文章
37 条回复
切换为时间正序
请发表友善的回复…
发表回复
shines77 2003-01-18
  • 打赏
  • 举报
回复
我有base64编码解码的,不过太不安全了
石牌桥网管 2003-01-18
  • 打赏
  • 举报
回复
代码不公开别人怎么破呢?
对了,听说ASP代码可以编译成字节码,而且一样的运行,是怎么编译的?
shines77 2003-01-18
  • 打赏
  • 举报
回复
每个人都可以破啊,Base64是一种非常简单而且常用的加密方法。
石牌桥网管 2003-01-18
  • 打赏
  • 举报
回复
shines(Othelloing):
你的算法非常棒,为什么你说太不安全呢?
shines77 2003-01-18
  • 打赏
  • 举报
回复
<%
'---------------------BASE64 MODULE-----------------------
dim sBASE_64_CHARACTERS
sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
sBASE_64_CHARACTERS = strUnicode2Ansi(sBASE_64_CHARACTERS)

Function strUnicodeLen(asContents)
'计算unicode字符串的Ansi编码的长度
dim asContents1
dim len1,i,k,asc1
asContents1="a"&asContents
len1=len(asContents1)
k=0
for i=1 to len1
asc1=asc(mid(asContents1,i,1))
if asc1<0 then asc1=65536+asc1
if asc1>255 then
k=k+2
else
k=k+1
end if
next
strUnicodeLen=k-1
End Function

Function strUnicode2Ansi(asContents)
'将Unicode编码的字符串,转换成Ansi编码的字符串
dim len1,i
dim varchar,varasc
dim varlow,varhigh,varHex
strUnicode2Ansi=""
len1=len(asContents)
for i=1 to len1
varchar=mid(asContents,i,1)
varasc=asc(varchar)
if varasc<0 then varasc=varasc+65536
if varasc>255 then
varHex=Hex(varasc)
varlow=left(varHex,2)
varhigh=right(varHex,2)
strUnicode2Ansi=strUnicode2Ansi & chrb("&H" & varlow) & chrb("&H" & varhigh)
else
strUnicode2Ansi=strUnicode2Ansi & chrb(varasc)
end if
next
End function

Function strAnsi2Unicode(asContents)
'将Ansi编码的字符串,转换成Unicode编码的字符串
dim len1,i
dim varchar,varasc
dim varlow,varhigh,varHex
strAnsi2Unicode = ""
len1=lenb(asContents)
if len1=0 then exit function
for i=1 to len1
varchar=midb(asContents,i,1)
varasc=ascb(varchar)
if varasc > 127 then
strAnsi2Unicode = strAnsi2Unicode & chr(ascw(midb(asContents,i+1,1) & varchar))
i=i+1
else
strAnsi2Unicode = strAnsi2Unicode & chr(varasc)
end if
next
End function

Function Base64encode(asContents)
'将Ansi编码的字符串进行Base64编码
'asContents应当是ANSI编码的字符串(二进制的字符串也可以)
dim lnPosition
dim lsResult
dim Char1
dim Char2
dim Char3
dim Char4
dim Byte1
dim Byte2
dim Byte3
dim SaveBits1
dim SaveBits2
dim lsGroupBinary
dim lsGroup64
dim m3,m4,len1,len2

len1=Lenb(asContents)
if len1<1 then
Base64encode=""
exit Function
end if

m3=Len1 Mod 3
if M3 > 0 then asContents = asContents & String(3-M3, chrb(0))
'补足位数是为了便于计算

if m3 > 0 then
len1=len1+(3-m3)
len2=len1-3
else
len2=len1
end if

lsResult = ""

For lnPosition = 1 To len2 Step 3
lsGroup64 = ""
lsGroupBinary = Midb(asContents, lnPosition, 3)

Byte1 = Ascb(Midb(lsGroupBinary, 1, 1)): SaveBits1 = Byte1 And 3
Byte2 = Ascb(Midb(lsGroupBinary, 2, 1)): SaveBits2 = Byte2 And 15
Byte3 = Ascb(Midb(lsGroupBinary, 3, 1))

Char1 = Midb(sBASE_64_CHARACTERS, ((Byte1 And 252) \ 4) + 1, 1)
Char2 = Midb(sBASE_64_CHARACTERS, (((Byte2 And 240) \ 16) Or (SaveBits1 * 16) And &HFF) + 1, 1)
Char3 = Midb(sBASE_64_CHARACTERS, (((Byte3 And 192) \ 64) Or (SaveBits2 * 4) And &HFF) + 1, 1)
Char4 = Midb(sBASE_64_CHARACTERS, (Byte3 And 63) + 1, 1)
lsGroup64 = Char1 & Char2 & Char3 & Char4

lsResult = lsResult & lsGroup64
Next

'处理最后剩余的几个字符
if M3 > 0 then
lsGroup64 = ""
lsGroupBinary = Midb(asContents, len2+1, 3)

Byte1 = Ascb(Midb(lsGroupBinary, 1, 1)): SaveBits1 = Byte1 And 3
Byte2 = Ascb(Midb(lsGroupBinary, 2, 1)): SaveBits2 = Byte2 And 15
Byte3 = Ascb(Midb(lsGroupBinary, 3, 1))

Char1 = Midb(sBASE_64_CHARACTERS, ((Byte1 And 252) \ 4) + 1, 1)
Char2 = Midb(sBASE_64_CHARACTERS, (((Byte2 And 240) \ 16) Or (SaveBits1 * 16) And &HFF) + 1, 1)
Char3 = Midb(sBASE_64_CHARACTERS, (((Byte3 And 192) \ 64) Or (SaveBits2 * 4) And &HFF) + 1, 1)

if M3=1 then
lsGroup64 = Char1 & Char2 & ChrB(61) & ChrB(61) '用=号补足位数
else
lsGroup64 = Char1 & Char2 & Char3 & ChrB(61) '用=号补足位数
end if

lsResult = lsResult & lsGroup64
end if

Base64encode = lsResult

End Function


Function Base64decode(asContents)
'将Base64编码字符串转换成Ansi编码的字符串
'asContents应当也是ANSI编码的字符串(二进制的字符串也可以)
dim lsResult
dim lnPosition
dim lsGroup64, lsGroupBinary
dim Char1, Char2, Char3, Char4
dim Byte1, Byte2, Byte3
dim M4,len1,len2

len1= Lenb(asContents)
M4 = len1 Mod 4

if len1 < 1 or M4 > 0 then
'字符串长度应当是4的倍数
Base64decode = ""
exit Function
end if

'判断最后一位是不是 = 号
'判断倒数第二位是不是 = 号
'这里m4表示最后剩余的需要单独处理的字符个数
if midb(asContents, len1, 1) = chrb(61) then m4=3
if midb(asContents, len1-1, 1) = chrb(61) then m4=2

if m4 = 0 then
len2=len1
else
len2=len1-4
end if

For lnPosition = 1 To Len2 Step 4
lsGroupBinary = ""
lsGroup64 = Midb(asContents, lnPosition, 4)
Char1 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 1, 1)) - 1
Char2 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 2, 1)) - 1
Char3 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 3, 1)) - 1
Char4 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 4, 1)) - 1
Byte1 = Chrb(((Char2 And 48) \ 16) Or (Char1 * 4) And &HFF)
Byte2 = lsGroupBinary & Chrb(((Char3 And 60) \ 4) Or (Char2 * 16) And &HFF)
Byte3 = Chrb((((Char3 And 3) * 64) And &HFF) Or (Char4 And 63))
lsGroupBinary = Byte1 & Byte2 & Byte3

lsResult = lsResult & lsGroupBinary
Next

'处理最后剩余的几个字符
if M4 > 0 then
lsGroupBinary = ""
lsGroup64 = Midb(asContents, len2+1, m4) & chrB(65) 'chr(65)=A,转换成值为0
if M4=2 then '补足4位,是为了便于计算
lsGroup64 = lsGroup64 & chrB(65)
end if
Char1 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 1, 1)) - 1
Char2 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 2, 1)) - 1
Char3 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 3, 1)) - 1
Char4 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 4, 1)) - 1
Byte1 = Chrb(((Char2 And 48) \ 16) Or (Char1 * 4) And &HFF)
Byte2 = lsGroupBinary & Chrb(((Char3 And 60) \ 4) Or (Char2 * 16) And &HFF)
Byte3 = Chrb((((Char3 And 3) * 64) And &HFF) Or (Char4 And 63))

if M4=2 then
lsGroupBinary = Byte1
elseif M4=3 then
lsGroupBinary = Byte1 & Byte2
end if

lsResult = lsResult & lsGroupBinary
end if

Base64decode = lsResult

End Function
'-----------------------------------------------------
%>

加密:
strPassword=Trim(Request.Form("password"))
if strPassword<>"" then
strPassword=strAnsi2Unicode(Base64encode(strUnicode2Ansi(strPassword)))
end if

解密:
strPassword=Trim(Request("password"))
if strPassword<>"" then
strPassword=strAnsi2Unicode(Base64decode(strUnicode2Ansi(strPassword)))
end if
逍遥小贼 2003-01-18
  • 打赏
  • 举报
回复
嗬嗬,关注一下
石牌桥网管 2003-01-18
  • 打赏
  • 举报
回复
shines(Othelloing)
请把你的base64编码解码发过来看借鉴一下
allforly 2003-01-18
  • 打赏
  • 举报
回复
b.com就这么严密?有没有禁止b.com以外的数据请求?
在b.com里设置一个测试环境。
<%
session("name") = "test"
response.write session("name")
%>
然后在b.com以外用xmlhttp获取这个数据看看,如果获取不了,那就另外想法子了。如果可以获取这个数据,那么就是代码里有错误,修改一下就可以了。
SeekTruth 2003-01-17
  • 打赏
  • 举报
回复


up一下,支持楼猪!
石牌桥网管 2003-01-17
  • 打赏
  • 举报
回复
a.com的数据库对 b.com 是保密的
只能在a.com上验证用户登录
allforly 2003-01-17
  • 打赏
  • 举报
回复
这样啊,那a.com的数据可以对b.com开放的么
石牌桥网管 2003-01-17
  • 打赏
  • 举报
回复
re: allforly(白衣胜血)
因为 b.com 上没有用户信息数据库
allforly 2003-01-17
  • 打赏
  • 举报
回复
关注中,顺便问一下,b.com为什么不做一个登陆界面?
sendee 2003-01-17
  • 打赏
  • 举报
回复
关注
石牌桥网管 2003-01-17
  • 打赏
  • 举报
回复
re: allforly(白衣胜血)
你这种方法我尝试了,有点问题
b.com的getSession.asp 不能得到name的值
李世垚 2003-01-17
  • 打赏
  • 举报
回复
给我打电话吧13072058247(下周一以前,过了不接)
李世尧
我累了不写了
allforly 2003-01-17
  • 打赏
  • 举报
回复
a.com里login.asp登陆成功后用xmlhttp发送用户名给b.com的getSession.asp里,
a.com里的login.asp:
如果检测用户名和密码成功,那么
......
dim xmlhttp
set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "POST","http://www.b.com/getSession.asp",true
xmlhttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
xmlhttp.send "name="&Request.Form("name")'这个Request.Form("name")是用表单提交给a.com的login.asp的
......

b.com的getSession.asp
<%
dim PreURL,ServerName
ServerName = "www.a.com"'a.com的服务器名称
PreURL = Request.ServerVariables("HTTP_REFERER")'获取前一路径
if Request.ServerVariables("REQUEST_METHOD")="POST" then
if PreURL="http://"&ServerName&"/login.asp" then'如果前一路径是a.com的login.asp里来的话,那么session用户名
session("name") = request.form("name")
'....你的其他操作
end if
end if
%>
amnoh 2003-01-17
  • 打赏
  • 举报
回复
up
石牌桥网管 2003-01-17
  • 打赏
  • 举报
回复
各位大虾,还有没有其他方法实现??
石牌桥网管 2003-01-17
  • 打赏
  • 举报
回复
re: zhusuhao(不以为然)
我那种实现方法是安不安全?别人能不能冒充从http://a.com/success.asp进入b.com/check.asp
加载更多回复(17)

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧