I wrote a code that opens my file and reads it and checks if it contains a certain username and password. but it's not working.
the method is always returning false and i don't know why.
my idea is to make my code read every line and split each line into 3 strings in an array, and then to validate if each string has the username or password. If it finds only one it goes to another line, if it finds both in the same line it breaks
public bool readFile(string username, string password, string path)
{
int cntr = 0;
string[] lines = File.ReadAllLines(path);
foreach (string line in lines)
{
cntr = 0;
string[] words = line.Split('-');
foreach (string element in words)
{
if (element == username || element == password)
cntr++;
}
if (cntr == 2)
break;
}
return cntr == 2? true : false;
}
i tried this, and i dont know why it's not working and since im working with interfaces and diff classes im having a hard time debugging it with message boxes
EDIT: i found out by debugging it that lines is always being null, for some reason. any help?