title: ChangePassword method in Java
body: <p>I'm working on a Java project, building a simple system, and it has some methods, one of them is "Change PassWord", I put the user's information (username &amp; password) in a text file called ("Users.txt").
  Now this is the description of the method: </p>
  
  <blockquote>
    <p>boolean ChangePassWord(): Asks the user to enter old password for
    verification, the user has at maximum three tries to enter correct old
    password; if not the password will not be changed and a message Box
    will be shown for the user. If user entered correct old password then
    he is authenticated to changer his password and asked to enter new
    password and confirming the new. Once if confirmed correctly the old
    password will be changed to the new one and a message box will be
    shown if wrong confirmation the old password will not be changed and a
    message box will be shown.</p>
  </blockquote>
  
  <p>I wrote this code:</p>
  
  <pre><code>boolean changePassword(){            
    String pass=JOptionPane.showInputDialog(null, "Enter old password: ", "Input", JOptionPane.QUESTION_MESSAGE);
    if(pass.equals(Password)) {
      String newpass=JOptionPane.showInputDialog(null, 
             "Enter new password: ", "Input", JOptionPane.QUESTION_MESSAGE);
      String connewpass=JOptionPane.showInputDialog(null, 
             "Enter confirming new password: ", "Input", 
              JOptionPane.QUESTION_MESSAGE);
      if(newpass.equals(connewpass)){
        Password= newpass;
        JOptionPane.showMessageDialog(null, "password changed ", "message", 
            JOptionPane.INFORMATION_MESSAGE);
        return true;
      }
      else
      JOptionPane.showMessageDialog(null, "Wrong Conferm ", "message", 
          JOptionPane.INFORMATION_MESSAGE);
  
    }
    else
      JOptionPane.showMessageDialog(null, "Wrong password ", "message", 
          JOptionPane.INFORMATION_MESSAGE);
  
    return false;
  }
  </code></pre>
  
  <p>but I think that it's wrong, and I need to use a loop I think.
  I hope you help me!</p>