Browse Source

refactoring: createUser method in CreateUser

main
Richard Schmidt 11 months ago
parent
commit
e9a8122953
  1. 12
      src/main/java/CreateUser.java
  2. 45
      user.json

12
src/main/java/CreateUser.java

@ -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

45
user.json

@ -1,47 +1,2 @@
[
{
"id": "d7ae19fe-4684-4d69-a73d-4cca612962a3",
"userName": "Test",
"password": "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92",
"birthday": "",
"firstName": "",
"surname": "",
"stayLoggedIn": false
},
{
"id": "2ec2c0c5-677c-4262-8958-fef98d11cc63",
"userName": "Test2",
"password": "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92",
"birthday": "",
"firstName": "",
"surname": "",
"stayLoggedIn": false
},
{
"id": "ccfcc294-48ad-49db-996f-d7c99a93bac9",
"userName": "testuser",
"password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8",
"birthday": "2000-01-01",
"firstName": "John",
"surname": "Doe",
"stayLoggedIn": false
},
{
"id": "27ffc70f-dd76-4765-81e3-76fde9b618e5",
"userName": "testUser",
"password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8",
"birthday": "1990-01-01",
"firstName": "John",
"surname": "Doe",
"stayLoggedIn": false
},
{
"id": "731fda82-6b51-4f3f-ae97-c9b01c9b4a1a",
"userName": "existinguser",
"password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8",
"birthday": "1990-01-01",
"firstName": "John",
"surname": "Doe",
"stayLoggedIn": false
}
]
Loading…
Cancel
Save