<?php  if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } function executePasswordReset(int $customerId): array { $user = Database::fetchOne("SELECT id, email FROM users WHERE id = :id", [':id' => $customerId]); if (!$user) return ['ok' => false, 'error' => 'User not found']; $tempPass = bin2hex(random_bytes(6)); $hash = password_hash($tempPass, PASSWORD_BCRYPT); Database::execute( "UPDATE users SET password_hash = :h, must_reset = 1, updated_at = NOW() WHERE id = :id", [':h' => $hash, ':id' => $customerId] ); Events::record(Events::CAT_MODIFY, 'user.password_reset', 'user', $customerId, ['admin_initiated' => true, 'must_reset' => true]); return ['ok' => true, 'temp_password' => $tempPass, 'user_id' => $customerId]; } function renderPasswordReset(int $customerId): string { $html = '<div class="pw-reset">'; $html .= '<div class="section-label">Reset Password</div>'; $html .= '<p style="font-size:12px;opacity:.5;margin-bottom:10px">Generates a secure random password. User must change on next login.</p>'; $html .= '<button class="btn btn-warning" data-action="resetCustomerPW" data-id="' . $customerId . '"><span>Generate New Password</span></button>'; $html .= '<div id="pw-result" style="display:none">'; $html .= '<div class="pw-display"><span class="section-label">Temporary Password (view once)</span>'; $html .= '<code id="pw-temp" class="pw-temp-code"></code>'; $html .= '<button class="btn btn-sm" id="pw-copy"><span>Copy</span></button>'; $html .= '</div></div>'; $html .= '</div>'; return $html; } 