I'm struggling to build a simple login method. (the worst thing is that I think the answer may be pretty obvious, so sorry for anything)
I have a type Client that has the client properties (name, email, username, password, age, etc.), that is storaged in a ClientRepository class. My idea is to compare the user and password til I have the right match and return the object Client logged, so I can access its properties outside.
I have two questions:
1 - The method below must have to return a Client type so I can access its properties later, right? Or theres a better way of doing a login method?
2 - What do I return in the "elses" below (when the login fails)?
Thanks
public Client logIn(String user, String password){
Cliente logged;
for(int i = 0; i < clients.size(); i++){
if(clients.get(i).getUser().equals(user)){
if(clients.get(i).getPassword().equals(password)){
logged = clients.get(i);
System.out.println("LOGIN SUCCESFULL");
return logged;
}else{
System.out.println("WRONG PASSWORD!");
}
}else{
System.out.println("USER DOESNT EXISTS");
}
}
}