I'm currently working on a project that requires me to store usernames and passwords into a text file, what i've got so far is that i'm able to write to the text file by using this
//string path = "C:\\Documents and Settings\\100000001791\\My Documents\\Visual Studio 2008\\Projects\\SmartDeviceProject1\\SmartDeviceProject1\\bin\\Debug\\usernames.txt";
string path = "\\Temp\\users.txt";
string line = Username.Text + "," + Password.Text ;
if (!File.Exists(path))
{
MessageBox.Show(Username.Text + " successfully created.");
FileStream cred = new FileStream(path, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(cred);
sw.WriteLine(line);
sw.Close();
cred.Close();
}
else
{
MessageBox.Show(Username.Text + " successfully created");
FileStream creds = new FileStream(path, FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(creds);
sw.WriteLine(line);
sw.Close();
creds.Close();
}
however, i have no idea how to go about using the data that i've created, what i've tried so far, is this.
private void LoginBtn_Click(object sender, EventArgs e)
{
string path = "C:\\Documents and Settings\\100000001791\\My Documents\\Visual Studio 2008\\Projects\\SmartDeviceProject1\\SmartDeviceProject1\\bin\\Debug\\usernames.txt";
//string path = "\\Temp\\loginlog.txt";
string line = Username.Text + "," + Password.Text + "," + DateTime.Now;
if (!File.Exists(path))
{
//FileStream users = new FileStream("\\Temp\\users.txt", FileMode.Open, FileAccess.Read);
FileStream users = new FileStream("C:\\Documents and Settings\\100000001791\\My Documents\\Visual Studio 2008\\Projects\\SmartDeviceProject1\\SmartDeviceProject1\\bin\\Debug\\users.txt", FileMode.Open, FileAccess.Read);
StreamReader su = new StreamReader(users);
if (line == su.ReadLine())
{
MessageBox.Show(Username.Text + " successfully logged in");
FileStream cred = new FileStream(path, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(cred);
sw.WriteLine(line);
sw.Close();
cred.Close();
AdminPage f2 = new AdminPage();
f2.Show();
}
else
{
MessageBox.Show("Incorrect Username/Password");
}
}
else
{
//FileStream users = new FileStream("\\Temp\\users.txt", FileMode.Open, FileAccess.Read);
FileStream users = new FileStream("C:\\Documents and Settings\\100000001791\\My Documents\\Visual Studio 2008\\Projects\\SmartDeviceProject1\\SmartDeviceProject1\\bin\\Debug\\users.txt", FileMode.Open, FileAccess.Read);
StreamReader su = new StreamReader(users);
if (line == su.ReadLine())
{
MessageBox.Show(Username.Text + " successfully logged in");
FileStream creds = new FileStream(path, FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(creds);
sw.WriteLine(line);
sw.Close();
creds.Close();
AdminPage f4 = new AdminPage();
f4.ShowDialog();
}
else
{
MessageBox.Show("Incorrect Username/Password");
}
}
Any help is deeply appreciated, and thank you so, so, so much.
I'm literally pulling my hair out over this :(