i am doing a project in asp.net. it uses a login feature which i have implemented with 2 textboxes and a button. nothing fancy.
so now i have to distinguish which kind of user is logged in as there are different roles like admin, user, guest...
so what i need to know is what Session["UserAuthentication"] is and what it does...i think that i can add this data to an extra table to log all the sessions...is this a good approach?
here is my authentication method:
protected void Button1_Click(object sender, EventArgs e)
{
string username = tbUsername.Text;
string pwd = tbPassword.Text;
string s;
s = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(s);
con.Open();
string sqlUserName;
sqlUserName = "SELECT Username, UserPassword FROM Benutzer WHERE Username ='" + username + "' AND UserPassword ='" + pwd + "'";
SqlCommand cmd = new SqlCommand(sqlUserName, con);
string CurrentName;
CurrentName = (string)cmd.ExecuteScalar();
if (CurrentName != null)
{
Session["UserAuthentication"] = username;
Session.Timeout = 1;
Response.Redirect("Default.aspx");
}
else
{
lblStatus.ForeColor = System.Drawing.Color.Red;
lblStatus.Text = "Benuztername/Password ungültig!";
}
}
sqlUserName = "SELECT Username, UserPassword FROM Benutzer WHERE Username ='" + username + "' AND UserPassword ='" + pwd + "'";-> so you wish someone to delete your DB right?