prepare(" SELECT pr.*, a.company_name, a.account_status FROM partner_password_resets pr JOIN affiliates a ON pr.affiliate_id = a.id WHERE pr.token = ? AND pr.expires_at > NOW() AND pr.used = 0 "); $stmt->execute([$token]); $affiliate = $stmt->fetch(); if (!$affiliate) { $errors[] = 'This reset link has expired or already been used. Please request a new one.'; } } catch (Exception $e) { $errors[] = 'An error occurred. Please try again.'; logPartnerActivity('Reset token validation error', ['error' => $e->getMessage()]); } } if ($_SERVER['REQUEST_METHOD'] === 'POST' && $affiliate && empty($errors)) { $password = $_POST['password'] ?? ''; $confirm = $_POST['confirm_password'] ?? ''; if (empty($password)) { $errors[] = 'Please enter a new password.'; } elseif (strlen($password) < 8) { $errors[] = 'Password must be at least 8 characters.'; } elseif (!preg_match('/[A-Z]/', $password)) { $errors[] = 'Password must contain at least one uppercase letter.'; } elseif (!preg_match('/[a-z]/', $password)) { $errors[] = 'Password must contain at least one lowercase letter.'; } elseif (!preg_match('/[0-9]/', $password)) { $errors[] = 'Password must contain at least one number.'; } elseif ($password !== $confirm) { $errors[] = 'Passwords do not match.'; } else { try { $hash = password_hash($password, PASSWORD_DEFAULT); $pdo->prepare(" UPDATE affiliates SET password_hash = ?, is_password_set = 1, account_status = 'active' WHERE id = ? ")->execute([$hash, $affiliate['affiliate_id']]); $pdo->prepare(" UPDATE partner_password_resets SET used = 1 WHERE token = ? ")->execute([$token]); logPartnerActivity('Password reset successful', ['affiliate_id' => $affiliate['affiliate_id'], 'email' => $affiliate['email']]); $success = true; } catch (Exception $e) { $errors[] = 'An error occurred while saving your password. Please try again.'; logPartnerActivity('Password reset save error', ['error' => $e->getMessage()]); } } } ?>
Partner Portal
Your password has been updated. You can now log in to the partner portal.
Go to LoginFor account: