authenticate.asp
<%
dim url
url = request.querystring
' 获得url. 
%> 
<html>
<body>
<form method=post action="/validate.asp">
  <input type=hidden name="url" value="<%=url%>">
 ' 将url保存到一个隐藏变量中.
  用户名:
  <input type=text name="txtname">
 口令:
  <input type=password name="txtpassword">
  <input type=submit>
</form>
</body></html>
    再用validate.asp文件获取传递给它的信息,从数据库中读取用户名和口令,以判断是否给用户授权。
validate.asp
<%
dim strusername, strpassword
strusername = request.form("txtname")
strpassword = request.form("txtpassword")
' 从表单中读取用户名和口令.
' 建立数据库连接...
dim strsql
strsql = "select * from validusers where username = " & _
    strusername & " and password = " & _
    strpassword
' 进行sql查询.
dim rs
set rs = conn.execute(strsql)
if rs.eof then
' 如果recordset不为空, 则用户名有效.
session("bolauthenticated") = true
' 将bolauthenticated 设为true.
    response.redirect request.form("url")
   ' 将用户传递到来过的url.
else
    response.redirect "/notvalidated.asp  
end if
%>
[1]
 
             我要评论
我要评论 
                                             
                                             
                                             
                                             
                                             
                                            
发表评论