code: private static char[] getPassword(TextDevice textDevice, String key) {
          boolean noMatch;
          char[] cred = new char[0];
          char[] passwd1;
          char[] passwd2;
          do {
              passwd1 = textDevice.readPassword("Please enter the password value for %s:", key);
              passwd2 = textDevice.readPassword("Please enter the password value for %s again:", key);
              noMatch = !Arrays.equals(passwd1, passwd2);
              if (noMatch) {
                  if (passwd1 != null) {
                      Arrays.fill(passwd1, ' ');
                  }
                  textDevice.printf("Password entries don't match. Please try again.\n");
              } else {
                  if (passwd1.length == 0) {
                      textDevice.printf("An empty password is not valid.  Please try again.\n");
                      noMatch = true;
                  } else {
                      cred = passwd1;
                  }
              }
              if (passwd2 != null) {
                  Arrays.fill(passwd2, ' ');
              }
          } while (noMatch);
          return cred;
      }
docs: Retrieves a password from the command line.
  @param textDevice  the system console.
  @param key   the password key/alias.
  @return the password.