I\'m creating this simple login code for an ATM machine. You enter username and password and you logs in, that works just great. Since I\'m not connecting to a database or a
There's a special method Console.readPassword()
for doing this, introduced in Java 6. You obviously couldn't run code like this on a real ATM, though! Swing has JPasswordField
which lets you do this kind of masking in a GUI, and one could imagine a Swing-based ATM window.
Michael, have a look at the description on Sun's website: https://web.archive.org/web/20120214061606/http://java.sun.com/developer/technicalArticles/Security/pwordmask
Or, if you're using Java 5 or newer, you can use this: How to mask a password in Java 5?
I assume this is a simulated ATM...
Dev has pointed out that password masking on the console is supported out of the box, so you can use that. However for anything but the most trivial of IO you'd be better off using Swing or a "curses-like" library:
If you have JavaSE 6 or newer you can use Console.readPassword()