0

I want the user to put his password into a Inputdialog. But I want that the text in the textfield are e.g. stars (***), so no one can read which password is written.

I use this Code for the Inputdialog (the password will be saved in the pw variable):

String pw = JOptionPane.showInputDialog("Password:");
Moritz
  • 139
  • 1
  • 10
  • Don't do the `new String(pass.getPassword())` in the accepted answer though, that will put your entered password into memory without encrypting, and with no control of when and if it will ever be removed (ie gc). – daniu Jun 28 '18 at 14:05

1 Answers1

-1

Use JPasswordField instead

There's a tutorial here http://www.zentut.com/java-swing/creating-password-field-by-using-jpasswordfield-class/

Rob Foran
  • 47
  • 4
  • 1
    An answer containing only a link is not a good answer. An answer needs to have enough information to be useful on its own, since other sites’ URLs change or disappear over time. – VGR Jun 28 '18 at 15:04