My program takes user name and password authentication from user before initialising the program,
so i created a button login to which i associated ActionListener as show below
login.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
if(txtUserName.getText().equals("Suraj") && (txtPwd.getPassword().toString()).equals("s123")){
dispose();
TimeFrame tFrame = new TimeFrame(userName);
tFrame.setVisible(true);
tFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
tFrame.setLayout(new GridLayout());
} else {
JOptionPane.showMessageDialog(null,"User name or password don't match","Acces Denied", JOptionPane.ERROR_MESSAGE);
}
Now the problem that occurs is even if i enter correct password, program displays an error mes
sage
getPassword()returns achar[]. ThetoString()on it does not return the contents as a string as you assume.Try
new String(txtPwd.getPassword()).equals("s123").However, there is a reason it is a
char[]and not a String. Try looking up the security aspect of it in the javadoc.