当前位置:首页 » 电脑办公 » 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