當前位置:首頁 » 電腦辦公 » asp中怎樣實現用戶名密碼登錄

asp中怎樣實現用戶名密碼登錄

發布時間: 2022-09-06 22:25:29

A. ASP用戶登錄

1.connection.asp里的代碼是:
<%
set conn=server.createobject("adodb.connection")
conn.open "provider=microsoft.jet.oledb.4.0;data source="&server.MapPath("student.mdb")
%>

2.yanzheng.asp里的代碼是:

<!--#include file="connection.asp"-->

<%
dim zhanghao,mima
zhanghao=request("zhanghao")
mima=request("mima")
if zhanghao="" then
%>
<script language=javascript>
alert("帳號為空");
location.href="denglu.asp"
</script>
<% end if %>
<% if mima="" then
%>
<script language=javascript>
alert("密碼為空");
location.href="denglu.asp"
</script>
<% end if %>
<%set rs=server.createobject("adodb.recordset")
rs.open "select * from student where zhanghao='"&zhanghao&"'",conn,1,3
if not rs.eof then
if mima=rs("mima") then
session("zhanghao")=zhanghao
Response.write("<script>location.href('index.asp')</script>" )
else
response.write ("<script>alert('用戶密碼錯誤');location.href('denglu.asp')</script>")
end if
end if
if rs.eof then
response.write ("<script>alert('用戶帳號錯誤');location.href('denglu.asp')</script>")
end if
set rs=nothing
rs.close

%>
二、

conn.asp
------------------
<%
Set conn=Server.CreateObject("ADODB.Connection")
connstr="DBQ="+server.mappath("haha.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)}"
conn.Open connstr
%>
--------------------

index.asp
--------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標題文檔</title>
</head>

<body>
<form name="form1" method="post" action="login.asp">
<table width="50%" height="108" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>用戶名:</td>
<td><input name="us" type="text" id="us"></td>
</tr>
<tr>
<td>密碼:</td>
<td><input name="pa" type="password" id="pa" value=""></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html>
----------------------

login.asp
----------------------
<!--#include file="conn.asp"-->
<%
us=replace(request.form("us"),"'","』")
pa=replace(request.form("pa"),"'","』")
%>
<%
set rs=server.createobject("adodb.recordset")
sql="select * from haha where us='"&us&"' and pa='"&pa&"'"
rs.open sql,conn,1,1
%>
<%
if rs.eof or rs.bof then
response.write"密碼錯誤~"
else
response.redirect"main.asp"
end if
%>
-------------------------

三、

連接資料庫(conn.asp)
<%
dim db,conn,connstr
db="@data.mdb"
set Conn = server.CreateObject("ADODB.Connection")
connstr="provider=microsoft.jet.oledb.4.0;data source="& server.MapPath("../data/"&db&"")
conn.Open connstr
%>
登錄頁面(login.asp)
<% @language=vbscript %>
<!--#include file="conn.asp"-->
<%
On Error Resume Next
dim uid
dim pwd
uid=trim(request.Form("uid")) '獲得用戶名
pwd=trim(request.form("pwd")) '獲得密碼
dim rs
set rs=server.createobject("adodb.recordset")

if uid<>"" then
dim sqlstr
sqlstr="select uid,pwd from admin where uid='"&replace(uid,"'","''")&"' and pwd='"&replace(pwd,"'","''")&"'"
rs.open sqlstr,conn,3,1
if not rs.eof then
session("uid")=uid
response.redirect "login_ok.asp" '重定位url
else
response.redirect "error.htm"
end if
else
response.redirect "error.htm"
end if
%>

或者查看http://www.chinaz.com/Program/Asp/0Z33DL2008.html

B. asp網頁設計中用戶登錄

<script language=javascript>
<!--
//驗證輸入
function CheckForm()
{
if(document.Login.uid.value=="")
{
alert("請輸入用戶名!");
document.Login.uid.focus();
return false;
}
if(document.Login.pwd.value == "")
{
alert("請輸入密碼!");
document.Login.pwd.focus();
return false;
}
if (document.Login.verifycode.value==""){
alert ("請輸入您的驗證碼!");
document.Login.verifycode.focus();
return(false);
}
}
-->
</script>
//表單
FORM name="Login" action="admin_check.asp" method="post" onSubmit="return CheckForm();">
<table width="682" height="170" border="0" align="center" cellpadding="0" cellspacing="0" background="images/backlogin.jpg"class="t_table">
<tr>
<th width="134" height="100" scope="col"></th>
<th width="53" scope="col"></th>
<th width="84" scope="col"></th>
<th width="100" scope="col"></th>
<th width="111" scope="col"></th>
<th width="44" scope="col"></th>
</tr>
<tr>
<td height="35"></td>
<td><span class="STYLE3">管理員:</span></td>
<td colspan="2"><input name="uid" class="inputname" type="text" id="uid" style="border: 1px solid #999999;FONT-SIZE: 9pt; height:21;width:165" size="16"></td>
<td rowspan="3"></td>
<td></td>
</tr>
<tr>
<td height="35"></td>
<td><span class="STYLE3">密碼:</span></td>
<td colspan="2"><input name="pwd" class="inputpassword" type="password" id="pwd" style="border: 1px solid #999999;FONT-SIZE: 9pt; height:21;width:165" size="16"></td>
<td></td>
</tr>
<tr>
<td height="35"></td>
<td>驗證碼:</td>
<td><input name=verifycode type=text value="<%If GetCode=9999 Then Response.Write "9999"%>" maxlength=4 size=10 style="border: 1px solid #999999; FONT-SIZE: 9pt;"></td>
<td><img src=GetCode.asp></td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="4" valign="middle">
<input name="button" type="image" src="images/login.gif" width="74" height="39" border="0"> <a href="../index.asp"><img src="images/quxiao.gif" width="75" height="39" border="0"></a></td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="4"></td>
<td></td>
</tr>
</table>
</FORM>
以上的放在同一個asp文件中
//admin_check.asp
<%response.Expires = 0%>
<!--#include file="conn.asp"-->
<!--#include file="md5.asp"-->
<%
'防SQL注入
function errsql(strget)
strcheck=strget
dim nothis(16)
nothis(0) = "net user"
nothis(1) = "xp_cmdshell"
nothis(2) = "/add"
nothis(3) = "exec%20master.dbo.xp_cmdshell"
nothis(4) = "net localgroup administrators"
nothis(5) = "select"
nothis(6) = "count"
nothis(7) = "asc"
nothis(8) = "char"
nothis(9) = "mid"
nothis(10) = "'"
nothis(11) = """"
nothis(12) = "insert"
nothis(13) = "delete"
nothis(14) = "drop"
nothis(15) = "truncate"
nothis(16) = "from"
for i=1 to ubound(nothis)
if instr(strget,nothis(i)) then
response.write "<script language=javascript>alert('輸入信息含有非法字元,請重新輸入!');history.go(-1);</script>"
response.End
end if
next
errsql = strcheck
end function
%>
<%
dim admin,password,webpassword
admin=errsql(trim(request("uid")))
webpassword=errsql(trim(request("pwd")))
password=md5(webpassword)
if cstr(session("getcode"))<>cstr(trim(request("verifycode"))) then
response.Write "<script LANGUAGE='javascript'>alert('請輸入正確的驗證碼!');history.go(-1);</script>"
response.end
end if

set rs=server.CreateObject("adodb.recordset")
rs.Open "select * from master where name='"&admin&"' and password='"&password&"' " ,conn,1,1
if not(rs.bof or rs.eof) then
if password=rs("password") then
session("admin")=trim(rs("name"))
session.Timeout=20
rs.Close
set rs=nothing
response.Redirect "index.asp"
else
response.write "<script LANGUAGE='javascript'>alert('對不起,登陸失敗!');history.go(-1);</script>"

end if
else
response.write "<script LANGUAGE='javascript'>alert('用戶名或密碼錯誤!');history.go(-1);</script>"

end if
%>
上面的conn.asp是連接Access資料庫的,資料庫和資料庫的表,自己建立沒問題吧

C. 在ASP.NET網站中登錄功能如何實現

一般現在的網站登錄系統都是先注冊保存你的信息於資料庫,然後登錄時去查找你是否存在,並給予一定許可權。.NET中,自己做登錄系統,根據你的需求做相應提示輸入框 並後台連接資料庫,為了安全性最好要有時限 還可以賦予不同的許可權等。

D. asp高手請教如何實現用戶名和密碼的登錄檢驗

補充裡面的是正確的,不用改,因為你不用寫數據嘛.
要分開判斷的話呢?
就得需要
IF多重判斷了
sql="select * from info where username='"&request.Form("username")&"'"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write("<Script language=JavaScript>alert('用戶名不存在');history.back();</Script>")
else
rs.close
sqlc="select * from info where username='"&request.Form("username")&"' and password='"&request.Form("password")&"'"
rs.open sqlc,conn,1,1
if rs.eof and rs.bof then
response.write("<Script language=JavaScript>alert('密碼不正確');history.back();</Script>")
else
session("username")=rsc("username")
session("password")=rsc("password")
end if
end if

E. 請問寫ASP.NET用戶名密碼登錄驗證需要哪些步驟

首先,在頁面上擺出文本框按鈕之類的控制項來接收用戶輸入的值。
第二,在資料庫中要有用戶表,至少存用戶名和密碼兩列。
第三,取得用戶輸入的值後 在資料庫中比對用戶名和密碼是否匹配。
第四,向用戶返回結果。

F. asp網頁設計中,怎麼實現用戶登錄,並且登陸狀態保持在當前頁面,類似於這種

一般用session
LoginName = request("LoginName") '登錄用戶名
Password = request("Password") '密碼
然後就select 資料庫是否有等於LoginName Password
如果有記錄。
查詢真實姓名
把姓名賦值到Session
Session("Employee_Name") = Employee_Name
,就完成了session

登陸的首頁判斷一下session是否為空,卻確定該用戶是否有登陸
if Session("Employee_Name")<>"" then
Server.Transfer "mmindex.asp"
response.end
end if