今天遇到个问题代码如下:
private void Button1_Click(object sender, EventArgs e)
{
string userid=zhanghao.Text.ToString();
string pwd=mima.Text.ToString();
string connectionstring="server=ZDC;database=shop;User ID=sa;pwd= ";
SqlConnection cnn=new SqlConnection(connectionstring);
SqlCommand cmd=cnn.CreateCommand();
cmd.CommandText="SELECT count(*) as icount from customer where userid='"+userid+"'";
cnn.Open();
SqlDataReader reader=cmd.ExecuteReader();
reader.Read();
string count=reader["icount"].ToString();
reader.Close();
if(count=="0")
{Label2.Text="帐号不存在";}
else
{
SqlCommand cmd1=cnn.CreateCommand();
cmd1.CommandText="select * from customer where userid='"+userid+"' "; SqlDataReader reader1=cmd1.ExecuteReader();
reader1.Read();
string mima1=reader1["password"].ToString();
reader1.Close();
if(mima1!=pwd)
{Label2.Text="密码不正确";}
else
{
Response.Cookies["customerid"].Value="+useid+";
Response.Redirect("webform1.aspx");}
}
cnn.Close();
}
}
}
最后密码一样时怎么比较都是不正确,但是mima1 和pwd经测试都一样啊。用"zdc321zdc"(密码)就能查出是一样的。
private void Button1_Click(object sender, EventArgs e)
{
string userid=zhanghao.Text.ToString();
string pwd=mima.Text.ToString();
string connectionstring="server=ZDC;database=shop;User ID=sa;pwd= ";
SqlConnection cnn=new SqlConnection(connectionstring);
SqlCommand cmd=cnn.CreateCommand();
cmd.CommandText="SELECT count(*) as icount from customer where userid='"+userid+"'";
cnn.Open();
SqlDataReader reader=cmd.ExecuteReader();
reader.Read();
string count=reader["icount"].ToString();
reader.Close();
if(count=="0")
{Label2.Text="帐号不存在";}
else
{
SqlCommand cmd1=cnn.CreateCommand();
cmd1.CommandText="select * from customer where userid='"+userid+"' "; SqlDataReader reader1=cmd1.ExecuteReader();
reader1.Read();
string mima1=reader1["password"].ToString();
reader1.Close();
if(mima1!=pwd)
{Label2.Text="密码不正确";}
else
{
Response.Cookies["customerid"].Value="+useid+";
Response.Redirect("webform1.aspx");}
}
cnn.Close();
}
}
}
最后密码一样时怎么比较都是不正确,但是mima1 和pwd经测试都一样啊。用"zdc321zdc"(密码)就能查出是一样的。
解决方案 »
- 请教一下GridView1.ClientID是什么来的?
- 附件上传
- AJAX xmlHttp.status==404问题求大神帮助
- 当checkbox为true时,textbox的enable为ture;反之,textbox的enable为false
- 大家好,有个问题请教,关于rss的~!谢谢
- 出错:无法验证资料 System.Web.Configuration.MachineKey.GetDecodedData
- 高手们快来看看~究竟是咋回事?
- 我想创建一个登陆界面,并连接到一个SQL或ACCESS数据库上,当用户输入用户名和密码时会到数据库查询并验证字段,请问我该怎么做呢?请各
- .net编的程序 在ie不同版本以及win98和win2000下运行不稳定!!!!有谁遇到类似问题,求解决方案!!
- 请教DataList数据绑定后的控制问题。
- 想做一个跟CSDN导航栏样的东西,但是里面的项要动态添加. 高分求!!!
- ASP.NET系统用户权限设计与实现
用"zdc321zdc" (密码)替换pwd就能查出是一样的
这,句估计有问题,没有将两边的空格清除,还有就是输入的信息也没有将空格清除。
还有你的程序可以稍微改进一下。SqlCommand cmd1=cnn.CreateCommand();
cmd1.CommandText="select * from customer where userid='"+userid+"' ";
SqlDataReader reader1=cmd1.ExecuteReader();
if(reader1.HasRows)
{
reader1.Read();
string mima1=reader1["password"].ToString();
判断密码
}
else
{
没有这个用户
}