Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

how to hide password on console

  Asked By: Donna    Date: Dec 24    Category: Java    Views: 2843
  

I am trying to make a logon screen in my java application where user will
enter username and password on command prompt.

I want to hide the password as user enters it....

1) how can we show " * " instead of characters user typing (as normally
shown in windows password boxes)
2) how can we achieve unix like password typing .like when user ype password
cursor remain still at one place ...

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Jonathan Harrison     Answered On: Dec 24

Here is a small sample program I made for you, it
shows how to choose whatever character you want for
you password.

import javax.swing.*;


public class Form extends JFrame
{

JTextField userName = new JTextField(15);
JPasswordField password  = new JPasswordField(15);

JTextArea comments = new JTextArea(4, 15);


public Form()
{

super("Feedback Form");
setSize(260,160);
setDefaultCloseOperation(EXIT_ON_CLOSE);

JPanel pane = new JPanel();

JLabel userNameLabel = new JLabel("Username: ",
SwingConstants.LEFT);
JLabel passwordLabel = new JLabel("Password: ",
SwingConstants.LEFT);
JLabel commentsLabel = new JLabel("Comments: ",
SwingConstants.LEFT);

password.setEchoChar('@');

comments.setLineWrap(true);
comments.setWrapStyleWord(true);

pane.add(userNameLabel);
pane.add(userName);
pane.add(passwordLabel);
pane.add(password);
pane.add(commentsLabel);
pane.add(comments);

setContentPane(pane);

//pack();

setVisible(true);
}


public static void main(String[] args)
{
Form frm = new Form();
}
}

 
Didn't find what you were looking for? Find more on how to hide password on console Or get search suggestion and latest updates.




Tagged: