Use
char[] ppaswd = pass.getPassword();
instead of
String ppaswd = pass.getText();
because
The method getText() from the type JPasswordField is deprecated.
As @MadProgrammer says:
The password is stored in a char array and you never convert it back to a String.
Strings live in the JVM for the life of JVM, making easier for nasty people examine the String pool and find the passwords.
Use a Map
to store username/password.
Map<String, char[]> map = new HashMap<String, char[]>();
put some initial values
map.put("test", "12345".toCharArray());
map.put("admin", "admin".toCharArray());
Here is the modified code
public void actionlogin() {
blogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String puname = txuser.getText();
char[] ppaswd = pass.getPassword();
if (map.keySet().contains(puname) && Arrays.equals(map.get(puname), ppaswd)) {
JOptionPane.showMessageDialog(null, "Correct Information", "Correct",
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "No Password/ID Found on System",
"Incorrect", JOptionPane.INFORMATION_MESSAGE);
txuser.setText("");
pass.setText("");
txuser.requestFocus();
if (radNew.isSelected()) {
if (!puname.equals("") && ppaswd.length > 0) {
map.put(puname, ppaswd);
}
JOptionPane.showMessageDialog(null,
"Re-enter your password and ID to confirm", "Information Saved",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
});
}