title: how to change a username and password stored in a text file only for the correct user
body: <p>i am currently making a application for my a level computing coursework. for my coursework i am required to make a login and registration system which requires me to store the user details in a text file this is only for my coursework so security isent important. my registration and login system works fine but i am also required to have a change account details screen in which the user can change their username and password.</p>
  
  <p>my problem is that my code that i have currently changes the password for every user with the same password ie if 2 users have password123 as a password both their passwordds gets changed to the new password </p>
  
  <pre><code> private void btnUpdatePassword_Click(object sender, EventArgs e)
      {
          string oldusername = txtBoxOldUsername.Text;
          string newusername = txtBoxNewUsername.Text;
          string oldpassword = txtBoxOldPassword.Text;
          string newpassword = txtBoxNewPassword.Text;
  
          string text = File.ReadAllText("users.txt");
          text = text.Replace(oldpassword, newpassword).Replace(oldusername, newusername);
          File.WriteAllText("users.txt", text);
      }
  </code></pre>
  
  <p>my problem is that i dont know how to change the password for only the correct user. it would be great if anyone could help thanks. also i HAVE to use a text file to do this meaning i cant use jason on xml etc</p>
  
  <p>this is what my text file looks like</p>
  
  <p>first user ~username~password</p>
  
  <p>second user ~username123~password</p>
  
  <p>third user ~username1234~password</p>
  
  <p>and this is the code i use to write to the text file </p>
  
  <pre><code>FileStream fileStream = new FileStream("users.txt", FileMode.Append, FileAccess.Write);
                          StreamWriter streamWriter = new StreamWriter(fileStream);
  
                          try
                          {
                              streamWriter.WriteLine(fullname + "~" + username + "~" + password + "~" + lastlogin);
  
                              MessageBox.Show("User registered successfully", "Registration Successful");
  
                              this.Hide();
                              var homeForm = new HomeForm();
                              homeForm.Closed += (s, args) =&gt; this.Close();
                              homeForm.Show();
  
                          }
                          catch (Exception)
                          {
                              MessageBox.Show("Error registering the user", "Please try again");
                          }
                          finally
                          {
                              streamWriter.Close();
                              fileStream.Close();
                          }
  </code></pre>