title: Wrong username and password C#
body: <p>I'm new to C#, and trying to make user login window. 
   Currently I'm trying to search from txt file and it works fine if I enter correct username. But the issue is when wrong username is entered- it stucks in loop.</p>
  
  <p>Actually the way I'm reading the string from textbox is wrong, Its not allowing me to enter new string before again comparing it from file if I enter wrong username. It keeps comparing the old value or null value
  Can anyone guide how this is done?</p>
  
  <pre><code>public void userpass()
  {
      int us = 0; //for user pass
      string readText2 = File.ReadAllText(pathuser);
      using (StreamReader sr2 = new StreamReader(pathuser))
      {
          string usernam = username.Text;
          string line;
          string[] lines = new String[500];
  
          while ((line = sr2.ReadLine()) != null)
          {
              lines[us] = line;
  
  
              if (lines[us] == usernam)
              {
                  check = 1;
                  MessageBox.Show(usernam);
                  Form2 f2 = new Form2();
                  this.Hide();
                  break;
              }
              us++;
          }
  
          if (lines[us] != usernam &amp;&amp; usernam != null)
          {
              this.DialogResult = DialogResult.None;
              DialogResult result = new DialogResult();
              result = MessageBox.Show("Invalid Username or Password?", 
                                       "Retry",
                                       MessageBoxButtons.OK);
              if (result == DialogResult.OK)
              {
                  username.Clear();
  
              }
          }
      }
  </code></pre>