I’m trying to create a program that will take user input (first, last name, password, re-enter password) and save its information to a file. Then when the program is opened for a second time it asks for a login, checking for the correct password. So far I have this, but when the button is clicked it throws an exception that the file is being used by another process.
private void enterButton_Click(object sender, EventArgs e)
{
string first = firstBox.Text;
string last = lastBox.Text;
string password = passwordBox.Text;
string reenter = reEnterBox.Text;
StreamWriter writer = File.CreateText(USER_PROFILE);
if (String.Equals(password, reenter))
{
writer.WriteLine(first);
writer.WriteLine(last);
writer.WriteLine(password);
string correct = password;
writer.Close();
}
}
private void Form1_Load(object sender, EventArgs e)
{
StreamReader reader = File.OpenText(USER_PROFILE);
string first = firstBox.Text;
string last = lastBox.Text;
string password = passwordBox.Text;
string reenter = reEnterBox.Text;
}
}
}