code and setup
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user