up
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* API - Cambiar contraseña de usuario administrador
|
||||
* Fecha: 3 de febrero de 2026
|
||||
*/
|
||||
|
||||
require_once '../config/config.php';
|
||||
|
||||
// Verificar autenticación
|
||||
requireAuthentication();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Cache-Control: no-cache, no-store, must-revalidate');
|
||||
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
|
||||
// Leer datos del request
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$userId = $input['user_id'] ?? null;
|
||||
$newPassword = $input['new_password'] ?? '';
|
||||
|
||||
if (!$userId) {
|
||||
throw new Exception('ID de usuario requerido');
|
||||
}
|
||||
|
||||
if (strlen($newPassword) < 6) {
|
||||
throw new Exception('La contraseña debe tener al menos 6 caracteres');
|
||||
}
|
||||
|
||||
// Encriptar contraseña
|
||||
$hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);
|
||||
|
||||
// Actualizar contraseña
|
||||
$db->execute(
|
||||
"UPDATE admin_users SET password_hash = ? WHERE id = ?",
|
||||
[$hashedPassword, $userId]
|
||||
);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Contraseña actualizada correctamente'
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log('Error changing admin password: ' . $e->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user