Files
breadcrumb-the-shire/core/Service/User/UserPasswordService.php

49 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2026-02-23 12:58:19 +01:00
<?php
namespace MintyPHP\Service\User;
2026-03-05 08:26:51 +01:00
use MintyPHP\Repository\User\UserWriteRepositoryInterface;
2026-02-23 12:58:19 +01:00
class UserPasswordService
{
public function __construct(
private readonly UserPasswordPolicyService $passwordPolicyService,
2026-03-05 08:26:51 +01:00
private readonly UserWriteRepositoryInterface $userWriteRepository
2026-02-23 12:58:19 +01:00
) {
}
public function validatePassword(
string $password,
string $password2,
bool $required,
?string $email
): array {
return $this->passwordPolicyService->validate($password, $password2, $required, $email);
}
public function passwordHints(): array
{
return $this->passwordPolicyService->hints();
}
public function passwordMinLength(): int
{
return $this->passwordPolicyService->minLength();
}
public function resetPassword(int $userId, string $password, string $password2): array
{
$errors = $this->passwordPolicyService->validate($password, $password2, true, '');
if ($errors) {
return ['ok' => false, 'errors' => $errors];
}
$updated = $this->userWriteRepository->setPassword($userId, $password);
if (!$updated) {
return ['ok' => false, 'errors' => [t('Password can not be updated')]];
}
return ['ok' => true];
}
}