top.window.location = '../../index.php'"; exit; } require_once __DIR__ . "/" . "../../includes/include_basics_only.php"; require_once __DIR__ . "/" . "../../includes/classes/ConnectPDO.php"; use includes\classes\ConnectPDO; use OcomonApi\Models\AccessToken; $conn = ConnectPDO::getInstance(); $configExt = getConfigValues($conn); $post = $_POST; // $localAuth = AUTH_TYPE == "SYSTEM"; $localAuth = (isset($configExt['AUTH_TYPE']) && $configExt['AUTH_TYPE'] == 'LDAP' ? false : true); $screenNotification = ""; $exception = ""; $data = []; $data['success'] = true; $data['message'] = ""; $data['cod'] = (isset($post['cod']) ? intval($post['cod']) : ""); $data['action'] = $post['action']; $data['field_id'] = ""; $data['current_pass'] = (isset($post['current_pass']) ? noHtml($post['current_pass']) : ""); $data['new_pass_1'] = (isset($post['new_pass_1']) ? noHtml($post['new_pass_1']) : ""); $data['new_pass_2'] = (isset($post['new_pass_2']) ? noHtml($post['new_pass_2']) : ""); $data['hash'] = (!empty($data['new_pass_1']) ? pass_hash($data['new_pass_1']) : ""); /* Validações */ if (!$localAuth) { $data['success'] = false; $data['message'] = message('warning', 'Ooops!', TRANS('PASSWORD_CHANGEABLE_IF_LOCAL_AUTH'),''); echo json_encode($data); return false; } if ($data['action'] == "edit") { if (empty($data['current_pass']) || empty($data['new_pass_1']) || empty($data['new_pass_2'])) { $data['success'] = false; $data['field_id'] = (empty($data['current_pass']) ? 'current_pass' : (empty($data['new_pass_1']) ? 'new_pass_1' : 'new_pass_2')); $data['message'] = message('warning', 'Ooops!', TRANS('MSG_EMPTY_DATA'),''); echo json_encode($data); return false; } if ($data['new_pass_1'] !== $data['new_pass_2']) { $data['success'] = false; $data['field_id'] = "new_pass_1"; $data['message'] = message('warning', 'Ooops!', TRANS('PASSWORDS_DOESNT_MATCH'),''); echo json_encode($data); return false; } $sql = "SELECT `password`, `hash` FROM usuarios WHERE user_id = :user_id "; try { $res = $conn->prepare($sql); $res->bindParam(':user_id', $data['cod'], PDO::PARAM_INT); $res->execute(); if ($res->rowCount()) { $row = $res->fetch(); /* Se tiver hash */ if (!empty($row['hash'])) { if (!password_verify($data['current_pass'], $row['hash'])) { $data['success'] = false; $data['field_id'] = "current_pass"; $data['message'] = message('warning', 'Ooops!', TRANS('ERR_LOGON'),''); echo json_encode($data); return false; } } elseif ($row['password'] !== $data['current_pass'] || empty($row['password'])) { $data['success'] = false; $data['field_id'] = "current_pass"; $data['message'] = message('warning', 'Ooops!', TRANS('ERR_LOGON'),''); echo json_encode($data); return false; } } } catch (Exception $e) { $exception .= "