I want to develop a simple login and registration system. The system needs to be able to register a user and allow them to login. Not only this i need to be able to identify who is the current user logged in.
User Class
import java.io.Serializable;
public class AuctionHouseUsers implements Serializable {
String userName;
String password;
public AuctionHouseUsers(String aUserName, String aPassword)
{
this.userName = aUserName;
this.password = aPassword;
}
public String getUserName()
{
return userName;
}
public void setUserName(String aUserName)
{
this.userName = aUserName;
}
public String getPassword()
{
return password;
}
public void setPassword(String aPassword)
{
this.password = aPassword;
}
}
AuctionHouse Class
public class AuctionHouseManager
ArrayList<AuctionHouseUsers> registeredUsers;
ArrayList<AuctionHouseUsers> logedInUsers;
public AuctionHouseManager()
logedInUsers = new ArrayList<AuctionHouseUsers>();
registeredUsers = new ArrayList<AuctionHouseUsers>();
}
public void registerUser(String username, string password)
{
AuctionHouseUsers registeredUser = new AuctionHouseUser(username,password);
registeredUsers.add(tempUser);
}
public void logIn(String username, string password)
{
AuctionHouseUsers logedInUser = new AuctionHouseUser(username,password);
logedInUsers.add(logedInUser);
}
How can i keep track of who (by there username) is currently logged in at this moment in time as i will be designing a gui.
If this is not an homework but an actual development project I would advise you to use Apache Shiro or Spring Security . Both offer support for authentication and access-control (and much more).
Hope this helps.