From ada29ea9570179c6d2d3f6c06234ef4e86d8823a Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Fri, 24 Apr 2026 13:19:15 +0300 Subject: [PATCH] store password hash in json user repo --- app/User/JsonUserRepository.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/User/JsonUserRepository.php b/app/User/JsonUserRepository.php index 61f74b0..954ec48 100644 --- a/app/User/JsonUserRepository.php +++ b/app/User/JsonUserRepository.php @@ -22,6 +22,7 @@ class JsonUserRepository implements UserRepository $users[] = [ 'id' => $id, 'email' => (string) $dto->email, + 'passwordHash' => $dto->passwordHash, 'isAdmin' => $dto->isAdmin, ]; $this->writeUsers($users); @@ -29,6 +30,7 @@ class JsonUserRepository implements UserRepository return new User( id: $id, email: $dto->email, + passwordHash: $dto->passwordHash, isAdmin: $dto->isAdmin, ); } @@ -39,11 +41,7 @@ class JsonUserRepository implements UserRepository foreach ($users as $data) { if ($data['id'] === $id) { - return new User( - id: $data['id'], - email: new EmailAddress($data['email']), - isAdmin: $data['isAdmin'] ?? false, - ); + return $this->hydrate($data); } } @@ -56,17 +54,23 @@ class JsonUserRepository implements UserRepository foreach ($users as $data) { if ($data['email'] === (string) $email) { - return new User( - id: $data['id'], - email: new EmailAddress($data['email']), - isAdmin: $data['isAdmin'] ?? false, - ); + return $this->hydrate($data); } } return null; } + private function hydrate(array $data): User + { + return new User( + id: $data['id'], + email: new EmailAddress($data['email']), + passwordHash: $data['passwordHash'] ?? '', + isAdmin: $data['isAdmin'] ?? false, + ); + } + private function readUsers(): array { if (!file_exists($this->filePath)) {