Hi guys
I need help in creating login page for my web application.
There are two users who will login to the system: Admin and User
in my database I have UserID, Password and Type
for column Type i have 'Administrator' and 'Users'
This is what i'm doing, but it keep redirect to the User.aspx regardless i.m entering id and password for Administrator or Users..
i don't know how to do it.. anyone can help??
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["UserConnectionString"].ConnectionString);
con.Open();
string cmdStr = "Select count(*) from [User] where UserID = '" + TextBox1.Text + "'";
SqlCommand CheckUser = new SqlCommand(cmdStr, con);
int temp = Convert.ToInt32(CheckUser.ExecuteScalar().ToString());
if (temp == 1)
{
string cmdStr2 = "select Type from [User] where UserID='"+TextBox1.Text+"' AND Password = '"+TextBox2.Text+"'";
SqlCommand cmd = new SqlCommand(cmdStr2, con);
Object TypeUser = cmd.ExecuteScalar();
con.Close();
if(TypeUser != null)
{
Label1.Visible = false;
Label1.Text = "";
if(TypeUser.ToString() == "Administrator")
Response.Redirect("Admin.aspx");
else
Response.Redirect("User.aspx");
}
else
{
Label1.Visible = true;
Label1.Text = "Invalid Credentials Entered, Try again";
}