commit feeafa632ba5233ab2c935afabec0c6192b10a9a Author: kevin Date: Sat Jul 12 13:53:42 2025 -0400 v1 diff --git a/dbconfig.php b/dbconfig.php new file mode 100644 index 0000000..0b5b20d --- /dev/null +++ b/dbconfig.php @@ -0,0 +1,6 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // Verificar usuario y contraseña actual + $stmt = $pdo->prepare("SELECT * FROM usuarios WHERE email = :email"); + $stmt->execute(['email' => $email]); + $user = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$user) { + $error = "Usuario no encontrado"; + } elseif (!password_verify($current_password, $user['password'])) { + $error = "Contraseña actual incorrecta"; + } else { + // Extraer usuario y dominio del email + $parts = explode('@', $email); + $user_api = $parts[0]; + $domain = $parts[1]; + + // Llamar a la API para cambiar contraseña + $data = [ + 'user' => $user_api, + 'host' => $domain, + 'newpass' => $new_password + ]; + + $ch = curl_init($api_host); + curl_setopt_array($ch, [ + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POST => true, + CURLOPT_HTTPHEADER => ['Content-Type: application/json'], + CURLOPT_POSTFIELDS => json_encode($data), + CURLOPT_USERPWD => "$api_username:$api_password", + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_SSL_VERIFYPEER => false + ]); + + $response = curl_exec($ch); + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if ($http_code === 200 && $response === '0') { + // Actualizar contraseña en la base de datos local + $new_hash = password_hash($new_password, PASSWORD_DEFAULT); + $update_stmt = $pdo->prepare("UPDATE usuarios SET password = :password WHERE email = :email"); + $update_stmt->execute([ + 'password' => $new_hash, + 'email' => $email + ]); + + $success = "Contraseña actualizada exitosamente"; + } else { + $error = "Error en el servidor XMPP: " . htmlspecialchars($response); + } + } + } catch (PDOException $e) { + $error = "Error de base de datos: " . $e->getMessage(); + } catch (Exception $e) { + $error = "Error general: " . $e->getMessage(); + } + } +} +?> + + + + + + + + Cambiar Contrasenna + + + + + +
+
+ + logo + IComunica + +
+

+ Cambiar Contraseña +

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+
+ +
+
+ +
+
+
+
+ + + + \ No newline at end of file