为什么用户名和密码验证不起作用?

chaliezhou 2009-07-22 04:12:00
我想得到的效果是:用户输入用户名和密码后点击“登录”,程序如果没有在数据库中发现用户输入的用户名或者密码错误,则给出窗口提示并返回登录界面。但是不知道为什么代码不起作用?麻烦大家帮忙看看!

源代码如下:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../../../connections/conn_b.asp"-->
<%
Dim rs,sqlstr
If Not Isempty(Request("login")) Then '判断表单是否提交
txt_name=Str_filter(Request.Form("txtName")) '获取用户名称
txt_passwd=Str_filter(Request.Form("txtPwd")) '获取用户密码
End if
If txt_name<>"" Then '判断用户名是否正确
Set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select P2,pPassword from T_JiChNR where P2='"&txt_name&"'",conn
'rs.open sqlstr,conn,1,1
If rs.eof Then
Response.Write("<script language='javascript'>alert('用户名不正确,请核实后重新输入!');window.location.href='login.asp';</script>")
Else
If rs("pPassword")<>txt_passwd Then
Response.Write("<script language='javascript'>alert('密码不正确,请确认后重新输入!');window.location.href='login.asp';</script>")
End If
End If
Else
errstr="请输入用户名!"
End If
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>系统登陆</title>
<style>
body{
margin-top:12.5%;
margin-left:25%;
background-color:#eee;
font-family:"宋体";
font-size:12px;
}
csm{
font-family:"宋体";
font-size:12px;
}
.input_out{
/*height:16px;默认高度*/
width:180px;
padding:2px 8px 0pt 3px;
height:20px;
border:1px solid #aaa;
background-color:#fff;
list-style-type:none;
}
a{
font-size:12px;
font-family:"宋体";
}
a.bot:link{ /*超链接正常下的样式*/
color:#333333;
text-decoration:none;
}
a.bot:visited{ /*访问过的超链接样式,此项颜色需要与正常下样式相同,否则在IE 6.0中会出错*/
color:#333333;
text-decoration:none;
}
a.bot:hover{ /*指针经过时的超链接样式*/
color:#0066FF;
text-decoration:none;
}
a.sev:link{ /*超链接正常下的样式*/
color:#0066cc;
text-decoration:none;
}
a.sev:visited{ /*访问过的超链接样式,此项颜色需要与正常下样式相同,否则在IE 6.0中会出错*/
color:#0066cc;
text-decoration:none;
}
a.sev:hover{ /*指针经过时的超链接样式*/
color:#0066ff;
text-decoration:none;
}
</style>

<script type="text/javascript">
function Mycheck(){
if(document.all.txtName.value==""){
alert('请输入用户名!');return false;}
if(document.all.txtPwd.value==""){
alert('请输入密码!');return false;}
}
</script>

</head>
<body>
<table width="460" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="460" height="237" valign="top" background="../../../picture/Cargo search/login.gif"><table width="459" height="235" border="0">
<tr>
<td height="88" colspan="2"> </td>
</tr>
<form action="C_Search.asp" method="post" name="form1" id="form1">
<tr>
<td width="153" height="23" align="right">用户名:</td>
<td width="296"><input class="input_out" type="text" name="txtName" id="txtName">
</td>
</tr>
<tr>
<td height="28" align="right">密码:</td>
<td><input class="input_out" type="password" name="txtPwd" id="txtPwd">
</td>
</tr>
<tr>
<td height="33" colspan="2" align="center"><input name="login" type="image" id="login" value="提交" src="../../../picture/Cargo search/register.gif" onClick="return Mycheck()"></td>
</tr>
</form>
<tr>
<td> </td>
<td align="right" valign="bottom"><a class="bot" href="../../../index.asp">返回首页</a></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
...全文
213 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
shaomingmark 2009-07-28
  • 打赏
  • 举报
回复
我自己网站的实现方式如下:

<%
set rs=server.CreateObject("adodb.recordset")
username=request.form("username")
userpwd=MD5(request.form("userpwd"))
sql="select * from users where username='"&username&"'"
rs.open sql,conn,1,1
if not rs.eof then
if rs("userpwd")<>userpwd then
response.Write("<script>alert('用户名或密码错误,请重新输入!');history.go(-1)</script>")
response.end
else
session("username")=username
session("lever")=rs("lever")
session("userpwd")=rs("userpwd")
session("id")=rs("id")
response.Redirect("index.asp")
end if
else
response.write("<script>alert('用户名或密码错误,请重新输入!');history.back()</script>")
response.end
end if
end if
%>


其中username为你输入的用户名,userpwd为你输入的密码(此处我用md5进行了加密处理),然后我根据你输入的用户名去查询,如何不存在直接返回。如果存在就进一步的判断密码是否正确,如果不正确这返回。正确就用session记下,然后进入后台的主界面。(session在后台进行判断程序是否已经登录)
tsxnb 2009-07-27
  • 打赏
  • 举报
回复
我也多次遇到代码没错,而又无法登录的这种怪事,
我的做法是关机睡上一觉,或者换一台电脑,故障自然消失。
chaliezhou 2009-07-24
  • 打赏
  • 举报
回复
非常感谢sy_binbin兄,可是我按照你的方法修改代码后IE浏览器依然无法登陆。有哪位朋友曾经遇到过类似问题?
sy_binbin 2009-07-23
  • 打赏
  • 举报
回复
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../../../connections/conn_b.asp"-->
<%
Dim rs,sqlstr
If Not Isempty(Request("login")) Then '判断表单是否提交
txt_name=Str_filter(Request.Form("txtName")) '获取用户名称
txt_passwd=Str_filter(Request.Form("txtPwd")) '获取用户密码
End if
If txt_name <>"" Then '判断用户名是否正确
Set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select P2,pPassword from T_JiChNR where P2='"&txt_name&"'",conn ,1,1
'rs.open sqlstr,conn,1,1
If rs.bof and rs.eof Then Response.Write(" <script language='javascript'>alert('用户名不正确,请核实后重新输入!');window.location.href='login.asp'; </script>")
response.End()
Else
If rs("pPassword") <>txt_passwd Then
Response.Write(" <script language='javascript'>alert('密码不正确,请确认后重新输入!');window.location.href='login.asp'; </script>")
response.End()
End If
End If
Else
errstr="请输入用户名!"
End If
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>系统登陆 </title>
<style>
body{
margin-top:12.5%;
margin-left:25%;
background-color:#eee;
font-family:"宋体";
font-size:12px;
}
csm{
font-family:"宋体";
font-size:12px;
}
.input_out{
/*height:16px;默认高度*/
width:180px;
padding:2px 8px 0pt 3px;
height:20px;
border:1px solid #aaa;
background-color:#fff;
list-style-type:none;
}
a{
font-size:12px;
font-family:"宋体";
}
a.bot:link{ /*超链接正常下的样式*/
color:#333333;
text-decoration:none;
}
a.bot:visited{ /*访问过的超链接样式,此项颜色需要与正常下样式相同,否则在IE 6.0中会出错*/
color:#333333;
text-decoration:none;
}
a.bot:hover{ /*指针经过时的超链接样式*/
color:#0066FF;
text-decoration:none;
}
a.sev:link{ /*超链接正常下的样式*/
color:#0066cc;
text-decoration:none;
}
a.sev:visited{ /*访问过的超链接样式,此项颜色需要与正常下样式相同,否则在IE 6.0中会出错*/
color:#0066cc;
text-decoration:none;
}
a.sev:hover{ /*指针经过时的超链接样式*/
color:#0066ff;
text-decoration:none;
}
</style>

<script type="text/javascript">
function Mycheck(){
if(document.all.txtName.value==""){
alert('请输入用户名!');return false;}
if(document.all.txtPwd.value==""){
alert('请输入密码!');return false;}
return true;}
</script>

</head>
<body>
<table width="460" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="460" height="237" valign="top" background="../../../picture/Cargo search/login.gif"> <table width="459" height="235" border="0">
<tr>
<td height="88" colspan="2">  </td>
</tr>
<form action="C_Search.asp" method="post" name="form1" id="form1">
<tr>
<td width="153" height="23" align="right">用户名: </td>
<td width="296"> <input class="input_out" type="text" name="txtName" id="txtName">
</td>
</tr>
<tr>
<td height="28" align="right">密码: </td>
<td> <input class="input_out" type="password" name="txtPwd" id="txtPwd">
</td>
</tr>
<tr>
<td height="33" colspan="2" align="center"> <input name="login" type="image" id="login" value="提交" src="../../../picture/Cargo search/register.gif" onClick="return Mycheck()"> </td>
</tr>
</form>
<tr>
<td>  </td>
<td align="right" valign="bottom"> <a class="bot" href="../../../index.asp">返回首页 </a> </td>
</tr>
</table> </td>
</tr>
</table>
</body>
</html>
chaliezhou 2009-07-23
  • 打赏
  • 举报
回复
现在问题已经解决了一部分:Firefox可以正常验证了,但是IE浏览器却无论如何都登陆不了??真的怪事了
jiufang98 2009-07-23
  • 打赏
  • 举报
回复
我曾经遇到过类似的问题,
就是:如果数据库里该字段的内容为空,不管你输入什么验证都能通过
sy_binbin 2009-07-23
  • 打赏
  • 举报
回复
<%
Dim rs,sqlstr
If Not Isempty(Request("login")) Then '判断表单是否提交
txt_name=Str_filter(Request.Form("txtName")) '获取用户名称
txt_passwd=Str_filter(Request.Form("txtPwd")) '获取用户密码
End if
If txt_name <>"" Then '判断用户名是否正确
Set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select P2,pPassword from T_JiChNR where P2='"&txt_name&"'",conn ,1,1
'rs.open sqlstr,conn,1,1
If rs.bof and rs.eof Then
Response.Write(" <script language='javascript'>alert('用户名不正确,请核实后重新输入!');window.location.href='login.asp'; </script>")
response.End()
Else
If rs("pPassword") <>txt_passwd Then
Response.Write(" <script language='javascript'>alert('密码不正确,请确认后重新输入!');window.location.href='login.asp'; </script>")
response.End()
End If
else
response.Redirect("登录成功需要显示的页面")
End If
Else
errstr="请输入用户名!"
End If
%>
chaliezhou 2009-07-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 sy_binbin 的回复:]
response.write rs("pPassword")

打印一下数据库里的密码,看和你输入的一样不
[/Quote]

谢谢sy_binbin,现在的情况是:不管我在用户名和密码输入框中输入什么内容,都会直接登陆进去。就好像前面的VBSCRIPT代码不起作用一样。
sy_binbin 2009-07-22
  • 打赏
  • 举报
回复
response.write rs("pPassword")

打印一下数据库里的密码,看和你输入的一样不
chaliezhou 2009-07-22
  • 打赏
  • 举报
回复
已回复的帖子不能再编辑了,只有贴在下面。

源代码如下:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../../../connections/conn_b.asp"-->
<%
Dim rs,sqlstr
If Not Isempty(Request("login")) Then '判断表单是否提交
txt_name=Str_filter(Request.Form("txtName")) '获取用户名称
txt_passwd=Str_filter(Request.Form("txtPwd")) '获取用户密码
End if
If txt_name <>"" Then '判断用户名是否正确
Set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select P2,pPassword from T_JiChNR where P2='"&txt_name&"'",conn
'rs.open sqlstr,conn,1,1
If rs.eof Then
Response.Write(" <script language='javascript'>alert('用户名不正确,请核实后重新输入!');window.location.href='login.asp'; </script>")
Else
If rs("pPassword") <>txt_passwd Then
Response.Write(" <script language='javascript'>alert('密码不正确,请确认后重新输入!');window.location.href='login.asp'; </script>")
End If
End If
Else
errstr="请输入用户名!"
End If
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>系统登陆 </title>
<script type="text/javascript">
function Mycheck(){
if(document.all.txtName.value==""){
alert('请输入用户名!');return false;}
if(document.all.txtPwd.value==""){
alert('请输入密码!');return false;}
}
</script>

</head>
<body>
<table width="460" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="460" height="237" valign="top" background="../../../picture/Cargo search/login.gif"> <table width="459" height="235" border="0">
<tr>
<td height="88" colspan="2">  </td>
</tr>
<form action="C_Search.asp" method="post" name="form1" id="form1">
<tr>
<td width="153" height="23" align="right">用户名: </td>
<td width="296"> <input class="input_out" type="text" name="txtName" id="txtName">
</td>
</tr>
<tr>
<td height="28" align="right">密码: </td>
<td> <input class="input_out" type="password" name="txtPwd" id="txtPwd">
</td>
</tr>
<tr>
<td height="33" colspan="2" align="center"> <input name="login" type="image" id="login" value="提交" src="../../../picture/Cargo search/register.gif" onClick="return Mycheck()"> </td>
</tr>
</form>
<tr>
<td>  </td>
<td align="right" valign="bottom"> <a class="bot" href="../../../index.asp">返回首页 </a> </td>
</tr>
</table> </td>
</tr>
</table>
</body>
</html>
chaliezhou 2009-07-22
  • 打赏
  • 举报
回复
我也不知道问题出在哪里,今天测试了一下午愣是没找到病根。我把样式表去掉,这样可能看起来会清楚些
岑子哥 2009-07-22
  • 打赏
  • 举报
回复
你把代码精简下,一步步测试,样式可以注释掉
这样调试会很方便,我没看出什么错误,好像是取值的问题吧
chaliezhou 2009-07-22
  • 打赏
  • 举报
回复
大家帮帮忙啊,顶一下!
1,项目功能:注册:用户输入用户名密码,邮箱等信息进行注册。其中用户名,密码,邮箱不能为空,密码不能少于6位,邮箱必须包含@符号等进行验证,若验证不通过会有提示框。注册成功实现自动登录,并跳转到主页面。登录:通过输入用户名密码进行后台数据库验证,若验证用户名密码在数据库中存在且正确即为成功,跳转到主页面,若不成功,提示用户名密码错误。浏览文章;可以浏览其他用户发的贴子或者文章。文章搜索:游客可以根据文章标题进行搜索功能。查看文章详细信息:可以查看文章的详细信息。查看热门文章:可以查看热门文章。板块信息查看:可以查看板块信息。点赞、评论、收藏:对文章可以发表评论,点赞,收藏,对自己发表的评论可以删除对喜欢的用户可以加关注或者取消关注。我的主页:可以查看个人信息和修改个人信息,同时也可以查看到我的关注,我的收藏信息和我的评论信息。我的相册:可上传本地照片到自己的相册,并对相册进行编辑操作。用户管理:可以查看所有用户信息,并删除。文章管理:审核用户发的文章有无敏感词汇,可审核通过和拒绝。板块管理:查询所有板块信息,新增,修改,删除板块。      适合做毕业设计参考项目。2,涉及技术:SSM框架,Tomcat3,开发环境:IDEA,MySQL数据库4,讲解方式:从环境安装,项目搭建,以及项目介绍等进行讲解5,包含资料:项目源码(含数据库文件),环境安装包,项目文档。

28,391

社区成员

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

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