web页面的用户登录界面

wangqiaoxp 2009-09-21 06:59:31
我写了一段代码,用来判断用户登录的,但是执行时不管怎么输都显示 "对不起,您输入的用户名错误!",程序代码如下,请高手指教
private void Button1_Click(object sender, System.EventArgs e)
{
if (this.username .Text =="")
{
this.RegisterStartupScript("提示", " <script language=\"javascript\"> alert('请输入用户名!'); </script> ");

return;
}

string SqlConn=System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
SqlConnection Conn=new SqlConnection(SqlConn);
Conn.Open();
string SqlStr0="select username,logid,pwd,qx,sfjh from [zy_user] where logid='"+this.username.Text+"' and sfzx='0'";
SqlCommand Comm0=new SqlCommand(SqlStr0,Conn);
SqlDataReader read0=Comm0.ExecuteReader();
if(read0.Read())
{

string sfjh=read0["sfjh"].ToString();
if (sfjh=="0")
{
this.err.Text="对不起,您是第一次登录必须修改密码!";


return;

}
string pwd=read0["pwd"].ToString();
if (!new Encode().DecodePassword(ref pwd,128))
{
}

if (pwd != this.pwd.Text)
{
this.err.Text="对不起,您输入的用户名或密码错误!";
this.pwd.Text="";
return;
}
else
{
Session["S_username"]=this.username.Text;
Session["S_qx"]=read0["qx"].ToString();
Session["S_username1"]=read0["username"].ToString();
Session.Timeout=500;
Response.Redirect("main.aspx");
read0.Close();
Conn.Close();
}
}
else
{
read0.Close();
Conn.Close();
this.err.Text="对不起,您输入的用户名或密码错误!";
this.username.Text="";
this.pwd.Text="";
}

}
...全文
715 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangqiaoxp 2009-09-21
  • 打赏
  • 举报
回复
可以了,谢谢 wuyq11
wuyq11 2009-09-21
  • 打赏
  • 举报
回复
代码还带优化
调试看看if(pwd.Trim().Equals(this.pwd.Text.Trim())

using(SqlConnection Conn = new SqlConnection(SqlConn))
{

}
wuyq11 2009-09-21
  • 打赏
  • 举报
回复
检查 string pwd = read0["pwd"].ToString(); 值
if (pwd.Trim().Equals(this.pwd.Text.Trim())
{
}
else
{
}
wangqiaoxp 2009-09-21
  • 打赏
  • 举报
回复
我现在输入正确的用户名和密码,显示的是“对不起,您输入的密码错误!"; ”
wangqiaoxp 2009-09-21
  • 打赏
  • 举报
回复
SQL语句没问题啊,试过了,是不是字符转换之间的问题啊??
binhu12332100 2009-09-21
  • 打赏
  • 举报
回复
来学习的……
Vinker 2009-09-21
  • 打赏
  • 举报
回复
我也要来看看
xiangchengboy 2009-09-21
  • 打赏
  • 举报
回复
应该是SQL语句查询有问题,先去查询分析器执行SQL了。
Lezen 2009-09-21
  • 打赏
  • 举报
回复
字符串最好用Equal()
王向飞 2009-09-21
  • 打赏
  • 举报
回复
事件探查器
看看SQL语句是怎么运行的
wangqiaoxp 2009-09-21
  • 打赏
  • 举报
回复
谢谢,可惜还是不可以~~~~怎么办,好急啊
gui0605 2009-09-21
  • 打赏
  • 举报
回复
单步调试,看看pwd和this.pwd.Text,要学会调试
shenymce 2009-09-21
  • 打赏
  • 举报
回复
if (pwd != this.pwd.Text.Trim()) 试一下
wangqiaoxp 2009-09-21
  • 打赏
  • 举报
回复
我调了很长时间,就一直是运行的 this.err.Text = "对不起,您输入的用户名错误!";
fengjian_428 2009-09-21
  • 打赏
  • 举报
回复
下个断点调试一下不就知道了
wangqiaoxp 2009-09-21
  • 打赏
  • 举报
回复
不对,上面的代码是一个示例程序的,应该是下面这行代码有问题:
protected void Button1_Click(object sender, EventArgs e)
{
if (this.username.Text == "")
{
this.RegisterStartupScript("提示", " <script language=\"javascript\"> alert('请输入用户名!'); </script> ");

return;
}

string SqlConn = System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
SqlConnection Conn = new SqlConnection(SqlConn);
Conn.Open();
string SqlStr0 = "select user,pwd from user_mxb where user='" + this.username.Text + " '";
SqlCommand Comm0 = new SqlCommand(SqlStr0, Conn);
SqlDataReader read0 = Comm0.ExecuteReader();
if (read0.Read())
{
string pwd = read0["pwd"].ToString();
if (pwd != this.pwd.Text)
{
this.err.Text = "对不起,您输入的密码错误!";
this.pwd.Text = "";
return;
}
else
{
Session["S_username"] = this.username.Text;
Session["S_username1"] = read0["username"].ToString();
Session.Timeout = 500;
Response.Redirect("main.aspx");
this.err.Text = "准备跳转页面!";
read0.Close();
Conn.Close();
}

}
else
{
read0.Close();
Conn.Close();
this.err.Text = "对不起,您输入的用户名错误!";
this.username.Text = "";
this.pwd.Text = "";
}

}

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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