-3
我的代码是假设检查是密码和用户名是否正确。尽管它没有做任何事情。我无法弄清楚为什么。我的代码没有任何反应
public virtual void checkUserNPass(string uNameExists, string pNameExists)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString); //creates sql connection object to the database via connection string
conn.Open();
string checkUserQuery = "select count (*) from users where UserName='" + uNameExists + "'"; //UserName query
string checkPasswordQuery = "select count (*) from users where Password='" + pNameExists + "'"; //Password query
SqlCommand commUser = new SqlCommand(checkUserQuery, conn);
SqlCommand commPass = new SqlCommand(checkPasswordQuery, conn);
int tempUser = Convert.ToInt32(commUser.ExecuteScalar().ToString());
int tempPassword = Convert.ToInt32(commUser.ExecuteScalar().ToString());
string user = commUser.ExecuteScalar().ToString().Replace(" ", "");
string password = commUser.ExecuteScalar().ToString().Replace(" ", "");
conn.Close();
if (tempUser != 0)
{
conn.Open();
if (tempPassword != 0)
{
conn.Open();
HttpContext.Current.Session["newUserSession"] = uNameExists;
HttpContext.Current.Response.Redirect("Manager.aspx");
conn.Close();
}//verifypassword
else
{
HttpContext.Current.Response.Write("Password is incorrect.");
conn.Close();
}
}
else
{
HttpContext.Current.Response.Write("Username is incorrect.");
conn.Close();
}
conn.Close();
}
}
}
protected void Button_Login_Click(object sender, EventArgs e)
{
string uNameExists = login_username.Text;
string pNameExists = login_password.Text;
NotLoggedIn checkLoginObj = new NotLoggedIn();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString); //creates sql connection object to the database via connection string
conn.Open(); //Open Connection
string checkuserQuery = "select count(*) from users where UserName='" + uNameExists + "'"; //UserName textbox ID
string checkPasswordQuery = "select count (*) from users where Password='" + pNameExists + "'";
SqlCommand comm = new SqlCommand(checkuserQuery, conn); //Command that allows connection
SqlCommand commPass = new SqlCommand(checkPasswordQuery, conn);
conn.Close();
if (!string.IsNullOrEmpty(uNameExists) && !string.IsNullOrEmpty(pNameExists))
{
checkLoginObj.checkUserNPass(uNameExists, pNameExists);
}
else
{
HttpContext.Current.Response.Write("Not working");
}
这么多,我不知道从哪里开始一点毛病此代码! – Fredou 2014-09-28 02:57:08
-1无法继续呈现此问题的方式。需要更多关于预期会发生什么,发生了什么(明显发生某些事情),发生什么不该发生的事情等详细信息... – 2014-09-28 02:58:40
基本上,当您单击Button然后button_login_click会触发。这是在一个单独的页面上。 – 2014-09-28 03:04:44