'Please fill in all fields.', 'type' => 'warning']; } elseif ($new_password !== $confirm_password) { $_SESSION['flash_message'] = ['text' => 'New passwords do not match.', 'type' => 'warning']; } else { // Fetch user's current hashed password $stmt = $pdo->prepare("SELECT password FROM users WHERE id = ?"); $stmt->execute([$user_id]); $user = $stmt->fetch(); // Verify current password if ($user && password_verify($current_password, $user['password'])) { // Hash the new password and update it $new_hashed_password = password_hash($new_password, PASSWORD_DEFAULT); $update_stmt = $pdo->prepare("UPDATE users SET password = ? WHERE id = ?"); if ($update_stmt->execute([$new_hashed_password, $user_id])) { $_SESSION['flash_message'] = ['text' => 'Password changed successfully.', 'type' => 'success']; } else { $_SESSION['flash_message'] = ['text' => 'Error changing password.', 'type' => 'danger']; } } else { $_SESSION['flash_message'] = ['text' => 'Incorrect current password.', 'type' => 'danger']; } } header('Location: profile.php'); exit; } require_once 'include/header.php'; ?>