I wrote a very basic login program in Java recently and I'm doing everything right, but I always get that the username doesn't match.
Here is the program:
public static void main(String[] args) {
//Creation
String username = JOptionPane.showInputDialog(null, "Create Username:");
int password = Integer.parseInt(JOptionPane.showInputDialog(null, "Create Password:\nOBS! Password Must Be Numbers!"));
JOptionPane.showMessageDialog(null, "Success! Login Created!\nTransferring you to login screen...");
//Login
String loginu = JOptionPane.showInputDialog(null, "Username:");
int loginp = Integer.parseInt(JOptionPane.showInputDialog(null, "Password:"));
if (username == loginu && password == loginp) {
JOptionPane.showMessageDialog(null, "Success!");
}else if (username == loginu && password != loginp) {
JOptionPane.showMessageDialog(null, "Password doesn't match.");
}else if (username != loginu && password == loginp) {
//always end up here!?
JOptionPane.showMessageDialog(null, "Username doesn't match.");
}else {
JOptionPane.showMessageDialog(null, "Something went wrong.");
}
}
}