title: Login and authentication system with .txt file
body: <p>I'm trying to code a simple login system with authentication.
  I first try to give user two choices of login or registering.
  Then if user chose to register, and the information will be stored in the .txt file to then used to compare with the login details to check whether this user existed or password is valid.
  I encountered a problem which is that when I registered two or more 'accounts',
  I'm able to login the other accounts other than the first account.
  It seems like something is missing in term of 'reading' through the .txt file, finding the data.</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
  
      File file = new File("database.txt");
      PrintWriter output = new PrintWriter(new FileWriter(file, true));
      Scanner input = new Scanner(file);
      Scanner keyboard = new Scanner(System.in);
      Customers customer = new Customers();
  
      System.out.println("1. Login");
      System.out.println("2. Register");
  
      int option = keyboard.nextInt();
  
      switch (option) {
          case 1:
              System.out.println("LOGIN PAGE");
              System.out.println("Username: ");
              String inpUser = keyboard.next();
  
              if (input.next().equals(inpUser)) {
                  System.out.println("Password: ");
                  String inpPass = keyboard.next();
                  if (input.next().equals(inpPass)) {
                      System.out.println("Login Succesful!");
                  } else {
                      System.out.println("Password is incorrect.");
                  }
              } else {
                  System.out.println("Username is incorrect.");
              }
              break;
  
          case 2:
              System.out.println("REGISTRATION PAGE");
              System.out.println("Username: ");
              String username = keyboard.next();
              customer.setUsername(username);
  
  
              System.out.println("Password: ");
              String password = keyboard.next();
              customer.setPassword(password);
  
              System.out.println("You've successfully registered! You may login now.");
  
              output.println(customer.getUsername());
              output.println(customer.getPassword());
  
              output.close();
              break;
  
          default:
              System.out.println("1 OR 2 PLEASE");
      }
      keyboard.close();
      input.close();
  }
  </code></pre>
  
  <p>Customers code</p>
  
  <pre><code>public Customers(){
  
  }
  
  public Customers(String username, String password) {
      this.username = username;
      this.password = password;
  }
  
  public String getUsername() {
      return username;
  }
  
  public String getPassword() {
      return password;
  }
  
  public void setUsername(String username) {
      this.username = username;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  </code></pre>
  
  <p>}</p>