A login system with two access levels
<p>I am attempting to create a login system that has two access levels. If the access level is 1 they recieve the 'carer home page', if the level is 2 they recieve the 'administrator page'. The login form has a variable that validates the username and password against the credentials in the database, when the user clicks the button and the tryLogin variable is returns true the access level is taken from the database where the username in the database matches the username text field</p>

<p>Instead of loading any of the forms the message invalid login credentials shows. Ive spent a long time working on this and im lost, i hope this explains the problem enough. </p>

<pre><code>public bool tryLogin(string uname, string pword)
        {
            MySqlConnection con = new MySqlConnection("host="";user="";password=""; database="";");
            MySqlCommand cmd = new MySqlCommand("SELECT * FROM Staff WHERE username = '" + uname + "' AND password ='" + pword + "';");
            cmd.Connection = con;
            con.Open();
            MySqlDataReader reader = cmd.ExecuteReader();



            if (reader.Read() != false)
            {
                if (reader.IsDBNull(0) == true)
                {
                    cmd.Connection.Close();
                    reader.Dispose();
                    cmd.Dispose();
                    return false;
                }
                else
                {
                    cmd.Connection.Close();
                    reader.Dispose();
                    cmd.Dispose();
                    return true;
                }
            }
            else
            {

                return false;

            }
        }



private void LoginBT_Click(object sender, EventArgs e)
        {


            if (tryLogin(uname.Text, pword.Text) == true)
            {
                MySqlConnection con = new MySqlConnection("host="";user="";password=""; database="";");
                MySqlCommand cmd2 = new MySqlCommand("SELECT access_level FROM Staff WHERE username = '" + uname + "';");

                cmd2.Connection = con;
                con.Open();


                MySqlDataReader reader = cmd2.ExecuteReader();

                if (cmd2.Equals("1"))

                {
                    this.Hide();
                    CarerHomePage CarerHomePage = new CarerHomePage();
                    CarerHomePage.Show();
                }

                if (cmd2.Equals("2"))
                {
                    this.Hide();
                    AdministratorHome AdministratorHome = new AdministratorHome();
                    AdministratorHome.Show();

                }


                else
                {
                    MessageBox.Show("Invalid Login Credentials");
                }



            }

        }

    }
}
</code></pre>
