当前位置: 移动技术网 > IT编程>开发语言>.net > 在ASP应用中验证用户身份(3)

在ASP应用中验证用户身份(3)

2019年01月15日  | 移动技术网IT编程  | 我要评论

火影博人传,筋斗云vpn,李存审出镞教子

三、用户身份验证

   为简单计,本文只讨论在服务器端的用户身份验证。登录页面是通过调用
aspsecurity.inc中的signuseron函数验证用户身份的。signuseron检查中
是否存在和用户输入的名字、密码匹配的记录:
function signuseron(asignon, apassword)
dim dict
用户输入的名字
asignon = lcase(trim(asignon))
用户输入的密码
apassword = lcase(trim(apassword))
提取用户记录转换成dictionary对象
set dict = getuser(asignon)
dict对象是否包含了合法的用户信息
if isuser(dict) then
if not dict("password") = apassword then
signuseron = false
session("msg") = "密码错误."
exit function
end if

更新最后访问时间
call updatelaston(asignon)

用sessionid (或不支持cookies时,id)标识用户记录
if not session("supportscookies") then
session("id") = getid()
dict.add "sessionid", session("id")
else
dict.add "sessionid", session.sessionid
end if

记录最后活动时间
dict.add "lastactivity", now()
在session中记录当前用户信息
set session("user") = dict
将当前用户加入正在访问用户列表
call addusertoapplication(dict)
signuseron = true
else
session("msg") = "用户名称错误"
signuseron = false
end if
end function



   如果用户输入的名字和密码与数据库中的记录匹配,signuseron函数返回
true。此时,用户被授权,session("user")变量包含了一个dictionary对象,其中
含有该用户的数据库记录的字段名称和值。另外,这里还把dictionary对象加入到
application("user")数组,这是为了便于获得当前正在访问安全站点的用户清
单。 signuseron用到了aspsecurity.inc中的许多子过程。由于大多数子过程都很
相似,下面只讨论其中的getuser。该函数先连接数据库,然后提取对应的用户记
录,最后将记录转换为dictionary对象并返回它,如下所示:
function getuser(asignon)
dim conn
dim r
set conn = openconnection()
set r = conn.execute("select * from users where users.signon=" &
asignon & "")
if err.number < > 0 then
输出错误信息
......
response.end
end if
if not r.eof then
set getuser = recordtodictionary(r)
else
set getuser = nothing
end if
r.close
set r = nothing
conn.close
set conn = nothing
end function


   如果用户在注册页面中单击的是注册按钮,则在经过必要的检查之后就可以在数
据库中生成新的用户记录了。注册成功的用户会自动进入安全页面,这一部分操作和
普通的登录过程是一样的。

   身份验证和注册操作都将错误信息存储在session("msg")变量中。这些错误信
息可以显示在返回给用户的html页面中:
< %
if session("msg") < > "" then
显示错误信息
......
session("msg") = ""
end if
%>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网