I have code here where it will check if the entered username and password are correct, my problem is that in my database I have a Username: "ADMIN" and Password: "ADMIN" but whenever I try to input "admin" for both username and password it still allows me to go to the main window which means my bool was true.
Here is my code:
public bool IsAccountValid(string userLogin, string userPassword)
{
bool flag = false;
try
{
accessToDatabase.OpeningDatabase();
String query = "SELECT * FROM Users where Username=@Username AND Password=@Password";
SqlCommand sqlCmd = accessToDatabase.Command(query);
sqlCmd.CommandType = CommandType.Text;
sqlCmd.Parameters.AddWithValue("@Username", userLogin);
sqlCmd.Parameters.AddWithValue("@Password", userPassword);
if (sqlCmd.ExecuteScalar() != null)
flag = true;
else
flag = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
accessToDatabase.ClosingDataBase();
}
return flag; //returns false if query does not exists...
}