title: Q: How to create a Login using StreamReader in C#
body: <p>
  So, I'm trying to create a <strong>Login</strong> system that gets the necessary information (name and password) from text file by using StreamReader. </p>
  
  <p>
  <strong>My Code:</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using System.IO;
  
  namespace PizzaOrder
  {
      public partial class Login : Form
      {
  
          public int attempts = 0;
          public bool success = false;
          public bool usernameSuccess = false;
          public bool passwordSuccess = false;
  
          public static string LogIn = @"C:\Users\P110095127\Documents\Visual Studio 2015\Projects\PizzaOrder\PizzaOrder\userDetails.txt";
  
          public Login()
          {
              InitializeComponent();
          }
  
          private void LoginButton_Click(object sender, EventArgs e)
          {
              string user = "";
              string passcode = "";
  
              int counter = 0;
  
              user = usernameBox.Text;
              passcode = passwordBox.Text;
  
              using (StreamReader readFile = new StreamReader(LogIn))
              {
                  counter = counter + 1;
                  string line;
                  while ((line = readFile.ReadLine()) != null)
                  {
                      var parts = line.Split(',');
                      user = parts[0];
                      passcode = parts[1];
                      attempts = Convert.ToInt32(parts[3]) + 1;
  
                      if (user == parts[1])
                      {
                          usernameSuccess = true;
                      }
                      else
                      {
                          MessageBox.Show("The username is incorrect");
                          attempts++;
                          break;
                      }
                      if (passcode == parts[2])
                      {
                          passwordSuccess = true;
                      }
                      else
                      {
                          MessageBox.Show("The password is incorrect");
                          attempts++;
                          break;
                      }
  
                      if (attempts == 3)
                      {
                          MessageBox.Show("The account has been blocked!");
                          this.Hide();
                      }
  
                      if (usernameSuccess &amp;&amp; passwordSuccess == true)
                      {
                          this.Hide();
                          Order Order = new Order();
                          Order.Show();
                      }
                  }
              }
          } 
  </code></pre>
  
  <p>
  I want the code to first check if the username is correct, if it is then continue to password, else I want the to display that the username has been entered incorrectly. The same thing goes for password. I have created a variable called 'attempts' and I want to increment the attempts by 1 every time they get username or password wrong. If the attempts reaches 3 then the account will be blocked. </p>
  
  <p>
  Every time I enter the correct username and password I still get the error message 'The username is incorrect'. Also, after 3 failed attempts it still doesn't hide the window but instead keeps saying the username is incorrect.</p>