I'm having a hard time coding in my login form. I need to authenticate users like admin and/or student. Can you please help me know the right query for this matter? I need this for my project. This is my code so far, this is for admin only. I want to include codes for student if they log in.
private void login_Click(object sender, EventArgs e)
{
try
{
string myConnection = "datasource = localhost;port=3306;username=root;password=";
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlCommand SelectCommand = new MySqlCommand("select username, password from library_sys.tbl_users where username = '" + this.txtusername.Text + "' and password = '" + this.txtpword.Text + "';", myConn);
MySqlDataReader myReader;
myConn.Open();
myReader = SelectCommand.ExecuteReader();
int count = 0;
while (myReader.Read())
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("Welcome to the LIBRARY MANAGEMENT SYSTEM!");
this.Hide();
Librarian lib = new Librarian();
lib.Show();
}
else
{
MessageBox.Show("Invalid username or password.");
myConn.Close();
}
myConn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}