Hi.
I have a basic login that creates a cookie if the credientials are fine. Ideally, the credentials should be checked against my stored procedure. My problem is that if the user enters invalid information, an error message is not visible. Can you tell me where I am erroring in my code below? The work occurs in the login button click:
protected void LoginBtn_Click(object sender, EventArgs e)
{
//check username, password, and status (is user active)
string username = Convert.ToString(usernm.Te
xt);
string password = Convert.ToString(passwordT
xt.Text);
string showUsers = ConfigurationManager.Conne
ctionStrin
gs["Revise
dTapeLibra
ry"].Conne
ctionStrin
g;
SqlConnection conn = new SqlConnection(showUsers);
SqlCommand comm = new SqlCommand("usp_LookupUser
TG", conn);
comm.Connection.Open();
comm.CommandType = CommandType.StoredProcedur
e;
comm.Parameters.AddWithVal
ue("@user"
, usernm.Text);
comm.Parameters.AddWithVal
ue("@passw
d", passwordTxt.Text);
comm.ExecuteNonQuery();
SqlDataReader myreader = comm.ExecuteReader();
if (myreader.HasRows)
{
while (myreader.Read())
{
string userrecord = Convert.ToString(myreader[
"UserID"])
;
int numValue = (int)myreader["TypeID"];
string myEmail;
if (myreader["email"] != DBNull.Value)
{myEmail = (string)myreader["email"];
}
else
{myEmail = "None Provided";}
string usertype = (string)myreader["UserType
"];
bool activeUser = (bool)myreader["active"];
string pw = (string)myreader["Password
"];
string usercred = (string)myreader["Username
"];
if (usernm.Text != usercred || passwordTxt.Text != pw)
{
Response.Write("Invalid Credentials");
}
else
{
Response.Redirect("/tl_fun
ctions/tap
elibstart.
htm");
HttpCookie aCookie = new HttpCookie("checkUser");
aCookie.Values["Site"] = "Tape Library Application";
aCookie.Values["LastVisit"
] = DateTime.Now.ToString();
aCookie.Values["Username"]
= usernm.Text;
aCookie.Values["Email"] = myEmail;
aCookie.Values["User Type"] = usertype;
string newTypeID = Convert.ToString(numValue)
;
aCookie.Values["My Type"] = newTypeID;
aCookie.Values["UID"] = userrecord;
Response.SetCookie(aCookie
);
}
}
}
comm.Connection.Close();
}