42 lines
1.2 KiB
Java
42 lines
1.2 KiB
Java
package models;
|
|
|
|
public abstract class User {
|
|
protected String username;
|
|
protected String password;
|
|
|
|
public User(String username, String password) {
|
|
this.username = username;
|
|
this.password = password;
|
|
}
|
|
|
|
public String getUsername() { return username; }
|
|
|
|
public boolean checkPassword(String password) {
|
|
return this.password.equals(password);
|
|
}
|
|
|
|
public static String validateUsername(String username) {
|
|
if (username == null || username.trim().isEmpty()) {
|
|
return "Username cannot be empty!";
|
|
}
|
|
if (username.length() < 3) {
|
|
return "Username must be at least 3 characters!";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static String validatePassword(String password) {
|
|
if (password == null || password.length() < 4) {
|
|
return "Password must be at least 4 characters!";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) return true;
|
|
if (obj == null || getClass() != obj.getClass()) return false;
|
|
User user = (User) obj;
|
|
return username.equalsIgnoreCase(user.username);
|
|
}
|
|
} |