|
|
@ -94,15 +94,25 @@ class CreateUser { |
|
|
|
|
|
|
|
// Function to create user with validation |
|
|
|
public static CreateUser createUser(String id, String userName, String password, String birthday, String firstName, String surname) { |
|
|
|
validateUserName(userName); |
|
|
|
validatePassword(password); |
|
|
|
|
|
|
|
return new CreateUser(id, userName, password, birthday, firstName, surname); |
|
|
|
} |
|
|
|
|
|
|
|
private static void validateUserName(String userName) { |
|
|
|
if (userName == null || userName.isEmpty()) { |
|
|
|
throw new IllegalArgumentException("Username cannot be empty"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static void validatePassword(String password) { |
|
|
|
if (password == null || password.isEmpty()) { |
|
|
|
throw new IllegalArgumentException("Password cannot be empty"); |
|
|
|
} |
|
|
|
if (password.length() < 6) { |
|
|
|
throw new IllegalArgumentException("Password must be at least 6 characters long"); |
|
|
|
} return new CreateUser(id, userName, password, birthday, firstName, surname); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Function to hash the password using SHA-256 algorithm |
|
|
|