I'm very new to Java, and I want to make a very simple login Java-program. Don't think about security issues and such in this example, I just need help to get it right. My "Account informations" has to be stored in an Array.
This is my code: -- MAIN --
import java.util.Scanner;
public class BATM {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String username;
String password;
System.out.println("Log in:");
System.out.println("Indtast username: ");
username = input.nextLine();
System.out.println("Indtast password: ");
password = input.nextLine();
users check = new users(username, password);
if(check.auth())
System.out.println("You are logged in");
}
}
-- users ---
public class users {
private String username;
private String password;
private String[][] accounts = {{"jesper", "abc123"},{"christian", "abc123"}};
public users(String user, String pass){
username = user;
password = pass;
}
public boolean auth(){
if((username == accounts[0][0]) && (password == accounts[0][1]))
return true;
else
return false;
}
}
I guess this should be a quite simple function, but for some reason the if-statment will never return "true".
What am I doing wrong?
Jesper.