41 lines
1.5 KiB
PHP
41 lines
1.5 KiB
PHP
<?php
|
|
// test_password.php - debug password verification
|
|
const BASE_PATH = __DIR__;
|
|
spl_autoload_register(static function (string $class): void {
|
|
$prefix = 'App\\';
|
|
if (!str_starts_with($class, $prefix)) return;
|
|
$relativeClass = substr($class, strlen($prefix));
|
|
$path = BASE_PATH . '/app/' . str_replace('\\', '/', $relativeClass) . '.php';
|
|
if (is_file($path)) require_once $path;
|
|
});
|
|
|
|
$config = require BASE_PATH . '/config/app.php';
|
|
\App\Support\Database::configure($config);
|
|
|
|
$db = \App\Support\Database::connection();
|
|
|
|
// Get user
|
|
$stmt = $db->prepare("SELECT email, password_hash FROM users WHERE email = :email");
|
|
$stmt->execute(['email' => 'admin@nordring.test']);
|
|
$user = $stmt->fetch();
|
|
|
|
echo "User: {$user['email']}\n";
|
|
echo "Hash length: " . strlen($user['password_hash']) . "\n";
|
|
echo "Hash starts with: " . substr($user['password_hash'], 0, 4) . "\n";
|
|
|
|
// Test password
|
|
$password = 'secret123';
|
|
echo "Password to check: '$password'\n";
|
|
echo "Password length: " . strlen($password) . "\n";
|
|
|
|
// Try password_verify
|
|
$verify = password_verify($password, $user['password_hash']);
|
|
echo "password_verify result: " . ($verify ? 'TRUE' : 'FALSE') . "\n";
|
|
|
|
// Try manually
|
|
echo "Manual check: " . (strpos($user['password_hash'], '$2y$') === 0 ? 'yes, starts with $2y$' : 'no') . "\n";
|
|
|
|
// Debug: Try a known hash
|
|
$testHash = password_hash('secret123', PASSWORD_DEFAULT);
|
|
echo "Test hash for 'secret123': $testHash\n";
|
|
echo "Verify test: " . (password_verify('secret123', $testHash) ? 'YES' : 'NO') . "\n"; |