登入界面,验证不同权限用户,以及验证码,密码后,实现登入
用户名:
密码:
验证码:
权限:(一个DropDownList控件,管理员和教师)
登入 取消
以上是前台界面
后台的代码是 ,我很奇怪的是用管理员账号密码可以登入,但是用教师的却不行,老是弹出:用户名或密码错误
管理员信息和教师信息都是存在同一个表里,以下是后台代码: 求指教!
protected void btnLogin_Click(object sender, EventArgs e)
{
if (String.Compare(Request.Cookies["yzmcode"].Value, txtIdentify.Text, true) != 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(),"yzjs","alert('验证码错误!')",true);
}
else
{
if (Page.IsValid)//使用验证控件后,在服务器端验证数据是否非法,
{
string strcon = ConfigurationManager.ConnectionStrings["connStr"].ToString();
SqlConnection conn = new SqlConnection(strcon);
try
{
conn.Open();
string struser = "select * from T_Users where UserName='" + txtUserName.Text.Trim() + "'and UserPass='" + txtPassword.Text.Trim() + "'and UserType='" + chooseRoles.SelectedValue + "'";
SqlCommand cmd = new SqlCommand(struser, conn);
SqlDataReader drd = cmd.ExecuteReader();
int lev = Convert.ToInt32(chooseRoles.SelectedValue);
if (drd.Read()&&lev==1)
{
Response.Redirect("Main.aspx");
}
else if (drd.Read()&& lev== 2)
{
Response.Redirect("Main2.aspx");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "yzjs", "alert('对不起,您输入的用户名或密码错误!')", true);
}
finally
{
conn.Close();
conn.Dispose();
}
}}}