if (RadioButton1.Checked) //管理员
{
DataSet ds = db.getDataset("select count(*) from users where Loginname='" + TextBox1.Text + "'and UserPwd='" + TextBox2.Text + "' and system=1", "users"); if (ds.Tables[0].Rows.Count > 0)
{
//登录成功后设置登录时间和标识
db.ExceNoQuery("update users set logintime='" + DateTime.Now + "',sign=1 where Loginname='" + TextBox1.Text + "'");
//存储登录用户名称
Session["loginname"] = TextBox1.Text;
//登录成功后跳转
Response.Redirect("Index.aspx");
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('用户名或密码错误')</script>");
} }
else
{
if (RadioButton2.Checked)//职员登录
{
DataSet ds = db.getDataset("select count(*) from users where Loginname='" + TextBox1.Text + "' and userpwd='" + TextBox2.Text + "' and system=0", "users"); if (ds.Tables[0].Rows.Count > 0)
{
db.ExceNoQuery("update users set logintime='" + DateTime.Now + "',sign=1 where loginname='" + TextBox1.Text + "'");
Session["loginname"] = TextBox1.Text;
Response.Redirect("Index.aspx");
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('用户名或密码错误')</script>"); }
}
} 点击登陆时无论密码验证是否正确都自动跳到主页面,请问大家是语法的错误还是SQL 的错误呢??
建议 TextBox1.Text 后面加上.trim() 把字符两边的空格过滤掉
错误在这,
就算密码不对,也会返回一个值为0的结果集
这样密码验证肯定不行.
这个来判断呢。。你是select count(*)
如果查到的是0,不也是会执行if里面的语句嘛。