forked from fa/breadcrumb-the-shire
Rename the top-level lib/ directory to core/ so the project root immediately communicates which code is core platform and which lives in modules/. PHP namespaces (MintyPHP\*) are unchanged — only the Composer PSR-4 path mapping moves from lib/ to core/. Module-internal lib/ directories (modules/*/lib/) are untouched. Updated across the full stack: - composer.json PSR-4 mapping - bootstrap entry points (web/index.php, bin/*, tests/bootstrap.php) - tooling configs (phpstan.neon, phpunit.xml, php-cs-fixer) - 26 architecture contract tests - enforcement-policy, guard-catalog, quality-gates - all documentation (CLAUDE.md, README, 25 docs/, .agents/skills/) - bin/qa-extended.sh search paths - .claude/settings.local.json permission paths Workflow: .agents/runs/CORE-LIB-RENAME-001/ (Analyst → Planner → Executor → Code Review (4 findings fixed) → Security Review → Acceptance Test → Finalizer) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
69 lines
2.4 KiB
PHP
69 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Service\User;
|
|
|
|
use MintyPHP\Service\I18n\TranslatesServiceText;
|
|
|
|
class UserPasswordPolicyService
|
|
{
|
|
use TranslatesServiceText;
|
|
|
|
private const PASSWORD_MIN_LENGTH = 12;
|
|
|
|
public function validate(string $password, string $password2, bool $required, ?string $email): array
|
|
{
|
|
$errors = [];
|
|
if ($required && $password === '') {
|
|
$errors[] = $this->translate('Password cannot be empty');
|
|
return $errors;
|
|
}
|
|
if ($password !== '' && $password !== $password2) {
|
|
$errors[] = $this->translate('Passwords must match');
|
|
}
|
|
if ($password === '') {
|
|
return $errors;
|
|
}
|
|
if (strlen($password) < self::PASSWORD_MIN_LENGTH) {
|
|
$errors[] = $this->translate('Password must be at least %d characters', self::PASSWORD_MIN_LENGTH);
|
|
}
|
|
if (!preg_match('/[A-Z]/', $password)) {
|
|
$errors[] = $this->translate('Password must include an uppercase letter');
|
|
}
|
|
if (!preg_match('/[a-z]/', $password)) {
|
|
$errors[] = $this->translate('Password must include a lowercase letter');
|
|
}
|
|
if (!preg_match('/\d/', $password)) {
|
|
$errors[] = $this->translate('Password must include a number');
|
|
}
|
|
if (!preg_match('/[^a-zA-Z0-9]/', $password)) {
|
|
$errors[] = $this->translate('Password must include a symbol');
|
|
}
|
|
if ($email !== null) {
|
|
$email = trim($email);
|
|
if ($email !== '' && stripos($password, $email) !== false) {
|
|
$errors[] = $this->translate('Password must not contain your email');
|
|
}
|
|
}
|
|
|
|
return $errors;
|
|
}
|
|
|
|
public function hints(): array
|
|
{
|
|
return [
|
|
['rule' => 'min', 'text' => $this->translate('At least %d characters', self::PASSWORD_MIN_LENGTH)],
|
|
['rule' => 'upper', 'text' => $this->translate('At least one uppercase letter')],
|
|
['rule' => 'lower', 'text' => $this->translate('At least one lowercase letter')],
|
|
['rule' => 'number', 'text' => $this->translate('At least one number')],
|
|
['rule' => 'symbol', 'text' => $this->translate('At least one symbol')],
|
|
['rule' => 'email', 'text' => $this->translate('Must not contain your email')],
|
|
];
|
|
}
|
|
|
|
public function minLength(): int
|
|
{
|
|
return self::PASSWORD_MIN_LENGTH;
|
|
}
|
|
|
|
}
|