I made a code which for change password in a local program i made. It is working almost very well, but i ran into a little issue. If i change the new password to "" (nothing), the file which are reading the password, doesnt works if i leave the field empty. It works fine if i type in a normal password like "hey". The password is stored in a txt file, so the problem is, that an empty JTextField doesnt equal an empty log file.. why? I need a fix of this. I would like it to work with the password (nothing), but some alternative fixes would be cool too.
This code checks password:
check is the string from readfile, and password is the string from my textfield.
if(event.getSource()==tf&&password.equals(check)){
try{
Runtime.getRuntime().exec("C:\\Windows\\System32\\notepad C:\\Applications\\Infostore.txt");
}catch(IOException ex){
ex.printStackTrace();
}
System.exit(1);
}else{
JOptionPane.showMessageDialog(null,"Wrong password");
}
The password creater is an ordinary filewriter, which gets content from textfield, and write it in a txt file.
Test the value of your JTextField before saving the password.
if (textField.getText()==null) passwd = "";