Im making a login application in C# and i want to save email, username and password in a single .txt file, how can i do this and then load the username and password when im loggin in and the email in the main window?
this is my login code:
string dir = textBox1.Text;
if (!Directory.Exists("data\\" + dir))
MessageBox.Show("User Dosen't Exist!", dir);
else
{
var sr = new StreamReader("data\\" + dir + "\\data.ls");
string encusr = sr.ReadLine();
string encpass = sr.ReadLine();
string encemail = sr.ReadLine();
sr.Close();
string decusr = Encryption.Encrypt.decrypt(encusr);
string decpass = Encryption.Encrypt.decrypt(encpass);
string decemail = Encryption.Encrypt.decrypt(encemail);
if (decusr == textBox1.Text && decpass == textBox2.Text)
{
MessageBox.Show("Welcome To Private Area", decusr);
Main_Form frm = new Main_Form();
frm.Show();
this.Hide();
}
else
{
MessageBox.Show("Password Or Username Is Wrong!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
and this the save code:
string dir = textBox1.Text;
Directory.CreateDirectory("Data\\" + dir);
var sw = new StreamWriter("Data\\" + dir + "\\data.ls");
string encusr = Encryption.Encrypt.encrypt(textBox1.Text);
string encpass = Encryption.Encrypt.encrypt(textBox2.Text);
string encemail = Encryption.Encrypt.encrypt(textBox3.Text);
sw.WriteLine(encusr);
sw.WriteLine(encpass);
sw.WriteLine(encemail);
sw.Close();
MessageBox.Show("User Was Successfully Created: " + textBox1.Text);
this.Close();