当前位置:编程学习 > asp >>

Discuz!NT 论坛整合ASP程序论坛教程

答案:
复制代码 代码如下:

登陆时记录cookies页面代码
<!--#include file="md5.asp"--> //32位md5加密文件,一定得调用,该文件到处有,我就不提供了
<%
dim Username,Password,Question,Answer,Expires,Verify
Username=replace(trim(Request.form("Username")),"'","''") //用户名
Password=replace(trim(Request.form("Password")),"'","''") //用户密码
Question=replace(trim(Request.form("Question")),"'","''") //密码问题
Answer=replace(trim(Request.form("Answer")),"'","''") //密码答案
Expires=replace(trim(Request.form("Expires")),"'","''") //cookies记录时长
Verify=replace(trim(Request.form("Verify")),"'","''") //验证码
//此处加上提交的验证,如xxx不能为空等或字段长度等
sql="select * from [dnt_users] where username='"&Username"'" //为了方便,此处我就不加过滤函数了,如你使用时一定加上,否则被注入
set rs=conn.execute(sql)
if rs.eof then
Response.Write ("<script>alert('提示!\n\n用户帐号错误!');history.back();</script>")
Response.end
else
if rs("password")<>md5(Password) then
Response.Write ("<script>alert('提示!\n\n用户密码错误!');history.back();</script>")
Response.end
else
if rs("secques")<>Answer then
Response.Write ("<script>alert('提示!\n\n安全答案错误!');history.back();</script>")
Response.end
else
Dim DES,DESCode
Set DES=Server.CreateObject("DiscuzNT.DES")
DESCode=DES.Encode(""&rs("password")"","Z143D2VBML") //Z143D2VBML为你的DES加密密钥,请用记事本打开CONFIG目录里的general.config文件,找到<Passwordkey>Z846D4VVZL</Passwordkey>这行,<Passwordkey>与</Passwordkey>中间的英文就是你的密钥,把密钥修改成你的文件的
Set DES=Nothing
Response.Cookies("dnt")("userid") = rs("uid")
Response.Cookies("dnt")("password") = DESCode
Response.Cookies("dnt")("tpp") = rs("tpp")
Response.Cookies("dnt")("ppp") = rs("ppp")
Response.Cookies("dnt")("pmsound") = rs("pmsound")
Response.Cookies("dnt")("invisible") = rs("invisible")
Response.Cookies("dnt")("referer") = "index.aspx"
Response.Cookies("dnt")("sigstatus") = rs("sigstatus")
Response.Cookies("dnt")("expires") = Expires
if Expires<>0 then
Response.Cookies("dnt").Expires = DateAdd("N", Expires, Now())
end if
Response.Cookies("dnt").Domain = ".xxx.com" //修改为你的域名,注意前面带.(点)
Response.Cookies("dnt").Secure = False
end if
end if
end if
rs.close
set rs=nothing
//此处加登陆后转向或向其他操作,具体你自己看着办
%>



===========================================================================================
注册页面代码(注册完后同时登陆状态)

<!--#include file="md5.asp"--> //32为md5加密文件,一定得调用,该文件到处有,我就不提供了
<%
dim Username,Password,CheckPassword,Email,Question,Answer,Verify
Username=replace(trim(Request.form("Username")),"'","''") //用户名
Password=replace(trim(Request.form("Password")),"'","''") //用户密码
CheckPassword=replace(trim(Request.form("CheckPassword")),"'","''") //密码验证
Question=replace(trim(Request.form("Question")),"'","''") //密码问题
Answer=replace(trim(Request.form("Answer")),"'","''") //密码答案
Expires=replace(trim(Request.form("Expires")),"'","''") //cookies记录时长
Verify=replace(trim(Request.form("Verify")),"'","''") //验证码
//此处加上提交的验证,如xxx不能为空等或字段长度等
sql="select * from [dnt_users] where username='"&Username"'" //为了方便,此处我就不加过滤函数了,如你使用时一定加上,否则被注入
set rs=conn.execute(sql)
if not rs.eof then
Response.Write ("<script>alert('提示!\n\n用户帐号已被注册使用!');history.back();</script>")
Response.end
end if
rs.close
set rs=nothing
sql="select * from [dnt_users] where Email='"&Email"'" //为了方便,此处我就不加过滤函数了,如你使用时一定加上,否则被注入
set rs=conn.execute(sql)
if not rs.eof then
Response.Write ("<script>alert('提示!\n\n电子邮箱已被注册使用!');history.back();</script>")
Response.end
end if
rs.close
set rs=nothing
ip = request.servervariables("http_x_forwarded_for")
if ip = "" then ip = request.servervariables("remote_addr")
sql="insert into [dnt_users] (username,nickname,password,secques,gender,adminid,groupid,groupexpiry,extgroupids,regip,joindate,lastip,lastvisit,lastactivity,lastpost,lastpostid,lastposttitle,posts,digestposts,oltime,pageviews,credits,extcredits1,extcredits2,extcredits3,extcredits4,extcredits5,extcredits6,extcredits7,extcredits8,avatarshowid,email,bday,sigstatus,tpp,ppp,templateid,pmsound,showemail,newsletter,invisible,newpm,newpmcount,accessmasks,onlinestate) values ('"&Username"',' ','"&MD5(Password)"','"&Answer"',0,0,10,0,' ','"&ip"','"&now()"','"&ip"','"&now()"','"&now()"','"&now()"',0,' ',0,0,0,0,0,'0.00','0.00','0.00','0.00','0.00','0.00','0.00','0.00',0,'"&Email"',' ',1,0,0,0,1,1,1,0,1,1,0,1)"
set rs=conn.execute(sql)
sql="select uid from [dnt_users] where username='"&Username"'" //为了方便,此处我就不加过滤函数了,如你使用时一定加上,否则被注入
set rs=conn.execute(sql)
Uid=rs(0)
sql="insert into [dnt_userfields] (uid,avatar,avatarwidth,avatarheight,authtime,authflag) values ('"&Uid"','avatars\common\0.gif',0,0,'"&now()"',0)"
set rs=conn.execute(sql)
sql="update [dnt_statistics] set totalusers=totalusers+1,lastusername='"&Username"',lastuserid='"&Uid"'"
set rs=conn.execute(sql)
sql="select * from [dnt_users] where username='"&Username"'" //为了方便,此处我就不加过滤函数了,如你使用时一定加上,否则被注入
set rs=conn.execute(sql)
if rs.eof then
Response.Write ("<script>alert('提示!\n\n用户帐号错误!');history.back();</script>")
Response.end
else
if rs("password")<>md5(Password) then
Response.Write ("<script>alert('提示!\n\n用户密码错误!');history.back();</script>")
Response.end
else
Dim DES,DESCode
Set DES=Server.CreateObject("DiscuzNT.DES")
DESCode=DES.Encode(""&rs("password")"","Z143D2VBML") //Z143D2VBML为你的DES加密密钥,请用记事本打开CONFIG目录里的general.config文件,找到<Passwordkey>Z846D4VVZL</Passwordkey>这行,<Passwordkey>与</Passwordkey>中间的英文就是你的密钥,把密钥修改成你的文件的
Set DES=Nothing
Response.Cookies("dnt")("userid") = rs("uid")
Response.Cookies("dnt")("password") = DESCode
Response.Cookies("dnt")("tpp") = rs("tpp")
Response.Cookies("dnt")("ppp") = rs("ppp")
Response.Cookies("dnt")("pmsound") = rs("pmsound")
Response.Cookies("dnt")("invisible") = rs("invisible")
Response.Cookies("dnt")("referer") = "index.aspx"
Response.Cookies("dnt")("sigstatus") = rs("sigstatus")
Response.Cookies("dnt")("expires") = 0
Response.Cookies("dnt").Domain = ".xxx.com" //修改为你的域名,注意前面带.(点)
Response.Cookies("dnt").Secure = False
end if
end if
rs.close
set rs=nothing
//此处加注册后转向或向另外一个用户表添加同步用户数据,具体你自己看着办
%>



===========================================================================================
编辑页面代码(编辑密码后无需重新登陆)

<!--#include file="md5.asp"--> //32为md5加密文件,一定得调用,该文件到处有,我就不提供了
<%
dim Username,Password,CheckPassword,Email,Question,Answer,Verify
Username=replace(trim(Request.form("Username")),"'","''") //用户名
Password=replace(trim(Request.form("Password")),"'","''") //用户密码
CheckPassword=replace(trim(Request.form("CheckPassword")),"'","''") //密码验证
Question=replace(trim(Request.form("Question")),"'","''") //密码问题
Answer=replace(trim(Request.form("Answer")),"'","''") //密码答案
Expires=replace(trim(Request.form("Expires")),"'","''") //cookies记录时长
Verify=replace(trim(Request.form("

上一个:在Win2003 64位下ASP无法连接Access数据库
下一个:ASP字符串大写转换成小写 ASP小写转换成大写 ucase lcase

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,