【急】连接数据库做身份验证【急】求各位大侠相助

dxwwym 2003-10-15 09:52:32
我想利用ACCESS数据库里的数据做身份认证的页面
比如:
数据库表1中有字段username和password字段
用户输入用户名和密码后如果正确即可跳到下一个页面修改密码和其他信息
如果错误则提示作物
其中数据库连接文件和关闭文件分别为conn.asp和close.asp
(还有就是怎么样才能保证数据库中USERNAME字段在注册的时候是唯一的)
小弟初学ASP还请各位大侠指教啊,问题有点愚蠢幼稚,真是不好意思!
不能给出所有代码就算给点提示或者用什么方法也行!
...全文
24 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dxwwym 2003-10-17
  • 打赏
  • 举报
回复
谢谢各位好心人!
yaozhg 2003-10-15
  • 打赏
  • 举报
回复
user=request("name")
pass=request("password")


连接好数据库并弄好其它东西,这不多说了,上面都有代码.

sql="select * from 表1 where username="&usernma&"" '判断有没有这个用户.
rs.open sql,conn,1,3
if not rs.eof then
有这个用户,不能注册
else
进行注册过程,把用户名和密码添加到数据库中
end if


liuguozhong 2003-10-15
  • 打赏
  • 举报
回复
我来个关键代码:
user=request("name")
pass=request("password")

set conn=server.CreateObject("adodb.connection")
conn.open "provider=microsoft.jet.oledb.4.0;data source="&server.mappath("guestbook.mdb")
set rs=server.CreateObject("adodb.recordset")
sql= "Select * From [users] Where name='" & user & "' And Password = '" & pass & "'"
rs.open sql,conn
if rs.eof then
response.Write "没有此用户或者密码错误,请注册!"
else
response.redirect "index.asp"
end if
ronanlin 2003-10-15
  • 打赏
  • 举报
回复
以上是登录验证代码,参考一下吧。
以下是添加代码。。
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#INCLUDE file="../Check/checking1.asp" -->
<!--#include file="../Connections/Connection.asp"-->
<html>
<head>
<META HTTP-EQUIV=REFRESH CONTENT="1;URL=AddUser.asp">
<link href="../Styles/StyleSheet.css" rel="stylesheet" type="text/css">
<title>网站后台管理系统</title></head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td>
<%
eUserName=Trim(Request.Form("UserName"))
eUserPassword=Trim(Request.Form("UserPassword"))
eUserTag=Trim(Request.Form("UserTag"))

Set rs = Server.CreateObject("ADODB.Recordset")
sql = "select UserName from Users where UserName='"&eUserName&"'"
rs.Open sql,strConn,adOpenDynamic,adLockReadOnly,adCmdText

If Not rs.Eof Then
rs.Close
Set rs = Nothing
Set strConn = Nothing
%>
<script language="javascript">
alert("该用户名已经存在!");
window.history.back();
</script>
<%
Else
rs.Close
Set rs = Nothing

If eUserName = "" Then
Response.Redirect("AddUser.asp")
Else
sqlInsert = "Insert Into Users (" & _
"UserName," & _
"UserPassword," & _
"UserTag) " &_
"values ('" & eUserName &_
"','" & eUserPassword & _
"'," & eUserTag & _
")"
Set cmdInsert = Server.CreateObject("ADODB.Command")
cmdInsert.ActiveConnection = strConn
cmdInsert.CommandText = sqlInsert
cmdInsert.CommandType = adCmdText
cmdInsert.Execute , , adExecuteNoRecords
Set cmdInsert = Nothing
Set strConn=Nothing
End If
end if
%>
<table width="200" border="0" cellspacing="0" cellpadding="0" align="center" class="NormalText">
<tr>
<td align="center">添加成功!</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

ronanlin 2003-10-15
  • 打赏
  • 举报
回复
<!--#include file="../Connections/Connection.asp"-->
<%
eUserName = Trim(Request.Form("UserName"))
eUserPassword = Trim(Request.Form("UserPassword"))

sqlUsers = "SELECT * from Users WHERE UserName='" & eUserName & "'"
Set rsUsers = Server.CreateObject("ADODB.Recordset")
rsUsers.Source = sqlUsers
rsUsers.ActiveConnection = strConn
rsUsers.CursorType = adOpenDynamic
rsUsers.LockType = adLockOptimistic
rsUsers.Open

Function checkLogin(name,password)
If rsUsers.Eof Then
CheckLogin="无此帐号"
ElseIf rsUsers("UserPassword") <> password Then
CheckLogin="密码错误"
Else
CheckLogin="成功登陆"
End If
End Function

strCheckLogin = CheckLogin(eUserName,eUserPassword)

If strCheckLogin = "成功登陆" Then
Session("UserName") = eUserName
Session("UserPassword")=eUserPassword
Session("UserTag")=rsUsers("UserTag")
Session("UserID")=rsUsers("UserID")
'Response.Write Session("UserName")
'Response.Write Session("UserPasswd")
Response.Redirect "../Index.asp"
End If
%>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body background="../images/back2.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<%
If strCheckLogin="无此帐号" Then
%>
<script language="javascript">
alert("无此帐号!请返回!");
window.history.back();
</script>
<%
ElseIf strCheckLogin="密码错误" Then
%>
<script language="javascript">
alert("密码错误!请返回!");
window.history.back();
</script>
<%
End If

rsUsers.Close
Set rsUsers=Nothing

Set strConn=Nothing
%>
</body>
</html>
dxwwym 2003-10-15
  • 打赏
  • 举报
回复
救命啊

没人帮忙吗?

哭死!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧