title: How to store usernames and passwords in java and call them in a different class
body: <p>I have 2 classes: one that creates a JPane login screen called ToolKit and another that is linked to the Toolkit called Register. When someone opens my app they register their information and it is saved into values like username and password and confirm password. I want to figure out how to store passwords and username and match the username with the registered password of the user input. Then I want to be able to use the stored username and password in my ToolKit class to allow access to login.</p>
  
  <p>I tried Array class storing my username and passwords in separate array fields and trying to link them but that seems not to work. I am trying to see if I should use a for loop to create switch statements or something random.</p>
  
  <p>Toolkit file:</p>
  
  <p>This is the login button:</p>
  
  <pre><code>JButton btnLogin = new JButton("Login");
  btnLogin.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
  </code></pre>
  
  <p>When you press login it clears the text fields:</p>
  
  <pre><code>String password = txtPassword.getText();
  String username = txtUsername.getText();
  //Dont forget condtion if statements. Like breaking down capitalization
  </code></pre>
  
  <p>I want to set "King" to what ever the user stores as username in the Register class and do the same for password.</p>
  
  <pre><code>        if(password.contains("King") &amp;&amp; username.contains("one")) {
              txtPassword.setText(null);
              txtUsername.setText(null);
          }
          else
          {
  </code></pre>
  
  <p>Just an Invalid Login Message this will be changed later to have more invalid login conditions.     </p>
  
  <pre><code>JOptionPane.showMessageDialog(null, "Invalid Login Details Have you Registered Yet?", "Login Error", JOptionPane.ERROR_MESSAGE);
              txtPassword.setText(null);
              txtUsername.setText(null);
  </code></pre>
  
  <p>Register Class:
  This is the second class and has a Jlabel that I turned into a button.</p>
  
  <pre><code>JLabel Register = new JLabel("Register");
  
  Register.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          Register.addMouseListener(new MouseAdapter() {
              @Override
              public void mouseClicked(MouseEvent e) {
  </code></pre>
  
  <p>When Register is clicked a few things will happen.</p>
  
  <p>As of right now when the Register Label is pushed it stores what ever the user input is into the variable name and password.</p>
  
  <p>How do i take those values and make them linked together and then store them and move them over to another class?   </p>
  
  <pre><code>String name =  userName.getText();
  String password = passwordField.getText();
  </code></pre>
  
  <p>I expect that while the app is open the user can create multiple account with different usernames and passwords that will stay linked together and will be able to go to the Toolkit class and Login with the password and username they created in the Register Class.</p>