Do you guys think this code will function properly?
public void LoadUser(string UserName, string Password)
{
try
{
using (StreamReader sr = new StreamReader("./Users/" + UserName + ".txt"))
{
string Line;
bool passCorrect = false;
bool userCorrect = false;
while ((Line = sr.ReadLine()) != null)
{
if (Line.Equals("UserName = " + UserName))
{
userCorrect = true;
}
if (Line.Equals("Password = " + Password))
{
passCorrect = true;
}
if (userCorrect && passCorrect)
{
MessageBox.Show("Username and password are correct");
}
}
}
}
catch (Exception)
{
MessageBox.Show("Account doesn't exist.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button1_Click(object sender, EventArgs e)
{
string user = textBox1.Text;
string pass = textBox2.Text;
LoadUser(user, pass);
}
And this is an example of the textfile:
UserName = Jayden
Password = lolcats
Thanks in advance!