.Contains
is not the problem.
The problem of this code is that, the way you have done it, any string that is in
login.txt
will match as a
username
and as a
password
.
So if
Username="a"
and
Password="a"
, it will be probably accepted by your code.
To ensure that you match a
Username
and matching
Password
, you need to check line by line
foreach (string Line in Lines) {
}
then split the Line in its components.
foreach (string Line in Lines) {
string[] Parts= Line.Split(",");
}
then check
Username
with
Parts[0]
and
Password
with
Parts[1]
.
UserFound= False;
foreach (string Line in Lines) {
string[] Parts= Line.Split(",");
if (Username == Parts[0] && Password == Parts[1]) {
UserFound= True;
break;
}
if (UserFound) {
}
}