asp登陸界面源碼
A. 求ASP登陸界面的源碼
<%dim db,conn,connstr
db="資料庫路勁"
set Conn = server.CreateObject("ADODB.Connection")
connstr="provider=microsoft.jet.oledb.4.0;Persist Security Info=False;data source=" & server.MapPath(db)
conn.Open connstr
IF Request("action")="login" Then verifycode=cstr(request("verifycode"))
if cstr(session("verifycode"))<>verifycode then
session("verifycode")=""
Response.Write("<script language=javascript>alert('請輸入正確的認證碼!');this.location.href='login.asp';</script>")
Response.End
else
session("verifycode")=""
end if
user=replace(trim(request.form("uName")),"'","''")
password=replace(trim(request.form("Password")),"'","''")
if instr(user,"%") or instr(user,"#") or instr(user,"?") or instr(user,"|") or instr(user,"'") then
response.write "<script language=javascript>alert('您的姓名含有非法字元!');this.location.href='login.asp';</script>"
response.end
end if
if instr(password,"%") or instr(password,"#") or instr(password,"?") or instr(password,"|") then
response.write "<script language=javascript>alert('您的密碼含有非法字元!');this.location.href='login.asp';</script>"
response.end
end if
uName=Trim(Request.Form("uName"))
Password=Trim(Request.Form("Password"))
IF uName<>"" And Password<>"" Then
SQL="Select * From adminname Where adminname='"& uName &"'"
Set RS=Server.CreateObject("ADODB.REcordset")
RS.Open SQL,Connstr,1,3
IF Not RS.Eof Then
IF Password=RS("adminpassword") Then
if rs("jb")="高級管理員" then
Session("cwz_youth1710")=uName
Session("cwz_youth1710_zj")=uName
Session("cwz_youth1710_dj")=uName
rs("LoginTimes")=rs("LoginTimes")+1
rs("LoginTime")=now()
rs("LoginIP")=Request.ServerVariables("REMOTE_ADDR")
rs.Update
Response.Redirect "index.asp"
elseif rs("jb")="中級管理員" then
Session("cwz_youth1710_zj")=uName
Session("cwz_youth1710_dj")=uName
rs("LoginTimes")=rs("LoginTimes")+1
rs("LoginTime")=now()
rs("LoginIP")=Request.ServerVariables("REMOTE_ADDR")
rs.Update
Response.Redirect "index.asp"
elseif rs("jb")="低級管理員" then
Session("cwz_youth1710_dj")=uName
rs("LoginTimes")=rs("LoginTimes")+1
rs("LoginTime")=now()
rs("LoginIP")=Request.ServerVariables("REMOTE_ADDR")
rs.Update
Response.Redirect "index.asp"
end if
else
response.write("<script language=javascript>alert('密碼錯誤!');this.location.href='login.asp';</script>")
response.end
End IF
else
response.write("<script language=javascript>alert('用戶名不存在!');this.location.href='login.asp';</script>")
response.end
End IF
else
response.write("<script language=javascript>alert('用戶名或密碼不能為空!');this.location.href='login.asp';</script>")
End IF
End IF Function getcode1()
Dim test
On Error Resume Next
Set test=Server.CreateObject("Adodb.Stream")
Set test=Nothing
If Err Then
Dim zNum
Randomize timer
zNum = cint(8999*Rnd+1000)
Session("verifycode") = zNum
getcode1= Session("verifycode")
Else
getcode1= "<img src=""getcode.asp"">"
End If
End Function
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>韶關學院50周年校慶網站後台管理登陸頁面</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
body,td,th {
font-size: 12px;
}
-->
</style></head><body><div align="center">
<table width="770" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="486"> <div align="center">
<form action="login.asp?action=login" method="post">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="88" height="30"><div align="right">用戶名:</div></td>
<td colspan="2"><input type=text name="uName" size=12 maxlength=20 style="background-attachment: scroll; background-repeat: repeat; font-size: 9pt; height: 18; width: 102; background-color: #FFFFFF; border: 1 solid #000000; background-position: none 0%"></td>
</tr>
<tr>
<td height="30"><div align="right">密碼:</div></td>
<td height="18" colspan="2"><input type=password name="Password" size=12 maxlength=16 style="background-attachment: scroll; background-repeat: repeat; font-size: 9pt; height: 18; width: 102; background-color: #FFFFFF; border: 1 solid #000000; background-position: none 0%"></td>
</tr>
<tr>
<td height="30"><div align="right">認證碼:</div></td>
<td width="112" height="30"><input class="input" type="text" name="verifycode" size="20" style="background-attachment: scroll; background-repeat: repeat; font-size: 9pt; height: 18; width: 102; background-color: #FFFFFF; border: 1 solid #000000; background-position: none 0%"></td>
<td width="100"><%=getcode1()%></td>
</tr>
<tr>
<td height="30" colspan="3"><div align="center"><font color="#000000">
<input type=submit value=' 提 交 ' name=Submit style="background-color: #DDDDDD; background-repeat: repeat; background-attachment: scroll; font-size: 9pt; height: 20; width: 50; border: 1px groove #000000; background-position: 0% 50%">
<input type=reset value=' 取 消 ' name=Submit style="background-color: #DDDDDD; background-repeat: repeat; background-attachment: scroll; font-size: 9pt; height: 20; width: 50; border: 1px groove #000000; background-position: 0% 50%">
</font></div></td>
</tr>
</table>
</form>
</div></td>
</tr>
</table>
</div>
</body>
</html>
B. ASP 用戶登陸驗證源碼
member.asp:
在頁面頭部加一個判斷就可以了:
<%
if Session("Uid")="" or Session("ifUserLogin")<>1 then
Response.redirect"login.asp"
else
'頁面代碼開始
end if
%>
Login.asp:
為了簡化程序,把登陸提交頁面和後台驗證程序放在同一個頁面中:
<!--#include file="Conn.asp"-->
<!--#include file="Md5.asp"-->
<%
'註:第一句是調用資料庫連接代碼,第二句代碼是為了調用函數給密碼加密
'請確保你的網站目錄下有這個文件,沒有的話可以從網上下載一個。
Dim Action
action=Trim(Request("action"))
if action="ChkLogin" then
call ChkLogin()
else
call UserLogin()
end if
Sub UserLogin
'用戶提交表單代碼開始
Response.write"<form action='Login.asp?action=ChkLogin' method='post'>"
Response.write"<table width='300' border='0' cellspacing='0' cellpadding='0'>"
Response.write"<tr>"
Response.write"<td width='80'>用戶名:</td>"
Response.write"<td width='220'><input type='text' name='UID'></td>"
Response.write"</tr>"
Response.write"<tr>"
Response.write"<td width='80'>密 碼:</td>"
Response.write"<td width='220'><input type='password' name='Pwd'></td>"
Response.write"</tr>"
Response.write"<tr>"
Response.write"<td colspan='2' align='center'><input type='submit' value='登錄'><input
type='reset' value='取消'></td>"
Response.write"</tr>"
Response.write"</table>"
Response.write"</form>"
End Sub
Sub ChkLogin()
'後台驗證部分開始
'因為每一個驗證碼的驗證機制不同,
'所以省略了對驗證碼的判斷。
Dim Rs,SQL,UID,PWD
UID=Trim(Request.form("uid"))
PWD=MD5(Request.form("pwd")) '這里調用了MD5給密碼加密
if UID="" Or PWD="" then
Response.write"<script language='Javascript'>alert('用戶名密碼不能為空');history.back(-1);</Script>"
Set Rs=server.CreateObject("adodb.recordset")
SQL="select * from [hyuser] where Uid='"&UID&"' and PWD='"&PWD&"' "
Rs.open SQL,conn,1,1
if Rs.eof or Rs.bof then
Response.write"<script language='Javascript'>alert('密碼錯誤!');history.back(-1);</Script>"
else
Session("uid")=UID
Session("ifUserLogin")=1
Response.redirect"member.asp"
end if
Set Rs=nothing
End Sub
%>