I have this code to save some csv data:
if (textBox2.Text ==textBox3.Text)
{
string username = textBox1.Text;
string password = textBox2.Text;
string Fullname = username "," password;
File.AppendAllText("Credentials.csv", Fullname);
DialogResult r = MessageBox.Show("Account Created ", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Clear();
textBox2.Clear();
this.Hide();
Form8 f = new Form8();
f.Show();
}
After running this code a few times, I expect a file with 3 rows and 2 columns as below:
ori,babmdt sami,123 yara,456
Whereas the file I created looks like this screenshot
How can I fix this?
CodePudding user response:
It's missing an end of line character at the end of each record. Change this:
string Fullname = username "," password;
to this:
string Fullname = $"{username},{password}\n";
But this is a profoundly unsafe way to handle passwords, and handling passwords is one of those things that's too important to do wrong, even for practice/learning projects. Go do some research on better patterns in this area before continuing.
CodePudding user response:
- You are just adding text to a CSV file -> Excel displays as you have added.
- @Igor made a good suggestion
- Why are you trying to store user/pass in plaintext?
- Please name your variables in a meaningful way