ASP使用者登入模組的設計

來源:互聯網
上載者:User

使用者登入驗證指令碼,Chkpwd.asp

以下為引用的內容:
<%
'=======使用者登入驗證指令碼=======
'如果尚未定義Passed對象,則將其定義為false,表示沒有通過驗證
If IsEmpty(Session("Passed")) Then
Session("Passed")=false
End If
 
'Session("Passed")=False,表示尚未通過驗證,則開始讀取從表單傳來的驗證資訊
If Session("Passed")=False Then
UserName=Request.Form("UserName")
UserPwd=Request.Form("UserPwd")
 
If UserName="" Then
Errmsg="提示:請輸入使用者名稱和密碼"
Else
'===================串連資料庫=====================
Set Conn= Server.CreateObject("ADODB.Connection")
Conn.Connectionstring= "Driver={SQL Server};Server=192.168.1.3;UID=sa;PWD=;Database=zcmrs"
Conn.open
'===================從表log中讀取使用者資料=====================
'定義RecordSet對象
Set rs=Server.CreateObject("ADODB.Recordset")
'設定Connection對象的ConnectionString
Set rs.ActiveConnection=Conn
'設定遊標類型
rs.CursorType=3
'開啟記錄集
rs.Open "Select username,password from erpuser Where username='"&UserName&"'"
'===================身分識別驗證======================
If rs.EOF Then
Errmsg="提示:使用者不存在或密碼錯誤"
Else
If UserPwd<>rs.Fields("password") Then
Errmsg="提示:登入失敗!密碼錯誤?"
Else '登入成功
Errmsg=""
Session("Passed")=True
Session("UserName")=rs.Fields("username")
'標識使用者權限 Session("UserID")=rs.Fields("UserID")
End If
End If
End If
End If
'經過登入不成功,則畫出登入表單
If Not Session("Passed")=True Then
%>
 
<html>
<head><title>無標題文檔</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 12px;font-weight:bold;margin-left:120px;outline:double}
-->
</style>
<style type="text/css">
<!--
.STYLE2 {font-size: 12px;font-weight:bold;outline:double;color:#FF3333}
-->
</style>
</head>
 
<body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0" bgcolor="#000000">
<div id=parent style="height:300;width:450;border-style:solid;border-color:#FFFFFF;margin-top:80px;margin-left:25%;margin-right:25%;background-color:#FFFFFF">
 
<div id=denglu style="font-size:12px;font-weight:bold;background-color:#0099FF;text- align:center;height:40px;"><br>ERP系統登入</div>
<form action="<%=request.ServerVariables("path_info")%>" method="post" name="MyForm" id="MyForm">
<p class="STYLE1">使用者名稱:<input name="UserName" type="text" id="UserName" size="18" maxlength="20">
</p>
<p class="STYLE1">密 碼:<input name="UserPwd" type="password" id="UserPwd" size="18" maxlength="20">
</p>
<p align="center" class="STYLE2"><%=Errmsg%> </p>
<p> 
<input type="submit" align="center" name="Submit" value="登入系統"> 
<input name="rege" type="button" align="center" onClick="location='register.asp'" id="rege" value="註冊使用者">
</p>
</form>
</div>
 
</body>
 
</html>
<%
'<p class="STYLE1">驗證碼:<input name="CheckCode" type="text" id="CheckCode" size="6" maxlength="4">
'<IMG style="MARGIN-RIGHT: 40px" alt="" src="common/getcode.asp"></p>
response.End
End If
%>

要訪問的頁面erp.asp

<以下為引用的內容:
<!--#include file="chkpwd.asp"-->
<body>
<div style='font-size:12px;font-weight:bold;border:1px solid #001;padding:4px;background:#FFCCFF;margin-top:0;'>歡迎使用ERP查詢系統,當前登入使用者 為:
<%
If Session("Passed")=True Then
Response.Write(Session("UserName"))
End If
%><a href="logout.asp">退出系統</a>
</div>
</body>
以上每次開啟erp.asp的時候,都首先執行Chkpwd.asp(),這樣可以有效防止未授權使用者訪問指定網頁.

logout.asp系統退出

<body>
<%
Session("Passed")=false
Session("UserName")=""
Response.Redirect("index.asp")
%>
</body>

使用圖片提交表單

以下為引用的內容:
<form name="form1" method="post" action="">
 
<td align="right"><input type="image" method="submit" name="submit" src="image/loginin.gif" width="70" height="21" alt="submit"></td>
 
</form>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.