title: Most desirable way to save password in a class - Java
body: <p>I have a two classes "User Profile" and "FingerprintProfile" which extend an abstract class "Profile".</p>
  
  <p>Profile:</p>
  
  <pre><code>/**
   * Template for User profiles or Fingerprint profiles
   */
  public abstract class Profile {
  
      /**
       * Profile Name
       */
      private String name;
  
      /**
       * Profile id
       */
      private int id;
  
      /**
       * Set the name of this profile
       * @param name
       */
      public void setProfileName(String name) {
          this.name = name;
      }
  
      /**
       * Set the id of this profile
       * @param name
       */
      public void setIdNumber(int id) {
          this.id = id;
      }
  
      /**
       * Get the name of this profile
       */
      public String getProfileName() {
  
          return name;
  
      }
  
      /**
       * Get the id of this profile
       */
      public int getIdNumber() {
          return id;
      }
  
  }
  </code></pre>
  
  <p>My next class is UserProfile</p>
  
  <pre><code>public class UserProfile extends Profile {
  
      /**
       * Users password
       */
      private char[] password;
  
      /**
       * Set User password
       * @param password
       */
      public void setPassword(char[] password){
  
          this.password = password;
  
      }
  
      /**
       * Get User password
       */
      public char[] getPassword(){
  
          return password;
  
      }
  
  }
  </code></pre>
  
  <p>Just looking at this class seems dodgy, it seems totally wrong to be able to retrieve the password like this (Even if the get method is <strong>private</strong>).</p>
  
  <p>It seems like I will be facing the same problem when making my FingerPrintProfile class as well as that holds a "FingerprintData" Object which inherently also needs to be secure.</p>
  
  <p>Does anybody know of a secure method, or preferably a pattern which people use to solve a scenario such as this one?</p>
  
  <p>Thanks !</p>
  
  <p><strong>Bonus Question</strong></p>
  
  <p>I made the abstract class to provide a template for both types of profile, and it seems there is a common ground between the fingerprint data and the text password. However, it is not possible to make an abstract field "password" which can potentially be a char array or a FingerprintData object. Any ideas?? </p>