I'm trying to make an application where you register a username and password then login, but when for some reason it won't recognize that the password is correct. Here is my code.
import javax.swing.JOptionPane; public class Main { String username; String password; public void start(){ int a = JOptionPane.showConfirmDialog(null, "Do you have an account?", "Login / Register", 1); if(a == JOptionPane.NO_OPTION){ regAccount(); } if(a == JOptionPane.YES_OPTION){ login(); } } public void login(){ String loginName = JOptionPane.showInputDialog("Please Enter Your Username"); String loginPass = JOptionPane.showInputDialog("Please Enter Your Password"); if(loginName == username){ JOptionPane.showMessageDialog(null, "Login succesful"); }else{ JOptionPane.showMessageDialog(null, "Login failed"); } } public void regAccount(){ username = JOptionPane.showInputDialog("Please Enter a Username:"); password = JOptionPane.showInputDialog("Please Enter a Password"); JOptionPane.showMessageDialog(null, "Your username is " +username, "Register", JOptionPane.PLAIN_MESSAGE); JOptionPane.showMessageDialog(null, "Your password is " +password, "Register", JOptionPane.PLAIN_MESSAGE); start(); } public static void main(String[] args){ Main main = new Main(); main.start(); } }
Sorry if my code is messy.