当前位置: 首页 > 图文教程 > 网络编程 > 编程10000问 > 如何对用户进行授权?

编程10000问
ASP问答集
asp中在JScript中使用RecordSet对象的GetRows
oblog_4.6_SQL 语句

编程10000问 中的 如何对用户进行授权?


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 39 ::
收藏到网摘: n/a

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]