<?php

namespace App\Support;

use Illuminate\Support\Facades\Hash;

class AdminSecurityPassword
{
    public static function matches(?string $providedPassword, ?string $adminPasswordHash = null, ?string $configuredPassword = null): bool
    {
        $providedPassword = trim((string) $providedPassword);
        if ($providedPassword === '') {
            return false;
        }

        $configuredPassword = trim((string) $configuredPassword);
        if ($configuredPassword !== '' && hash_equals($configuredPassword, $providedPassword)) {
            return true;
        }

        $adminPasswordHash = (string) $adminPasswordHash;
        if ($adminPasswordHash === '') {
            return false;
        }

        return Hash::check($providedPassword, $adminPasswordHash);
    }
}
