hash password in create user

This commit is contained in:
Yisroel Baum 2026-04-24 13:18:44 +03:00
parent 016e98412b
commit 0f179e53c2
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -21,6 +21,16 @@ class CreateUser
throw new BadRequestException('email is required');
}
if ($dto->password === null) {
throw new BadRequestException('password is required');
}
if (strlen($dto->password) < 8) {
throw new BadRequestException(
'password must be at least 8 characters'
);
}
$email = new EmailAddress($dto->email);
if ($this->userRepo->findByEmail($email) !== null) {
throw new BadRequestException('email already taken');
@ -28,6 +38,7 @@ class CreateUser
$this->userRepo->create(new CreateUserDto(
email: $email,
passwordHash: password_hash($dto->password, PASSWORD_DEFAULT),
isAdmin: $dto->isAdmin,
));
}