Bot & Automation

Treding Forex Ai

/root/hermes-projects/Treding Forex Ai

mt5-bridge/scripts/set-mt5-password.ps1 text
$ErrorActionPreference = "Stop"

$bridgeRoot = Split-Path -Parent $PSScriptRoot
$envPath = Join-Path $bridgeRoot ".env"

if (-not (Test-Path -LiteralPath $envPath)) {
  throw ".env bridge belum ada."
}

$securePassword = Read-Host "Masukkan password MT5 Exness" -AsSecureString
$bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($securePassword)
try {
  $plainPassword = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr)
} finally {
  [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
}

if (-not $plainPassword) {
  throw "Password kosong."
}

$envText = Get-Content -LiteralPath $envPath -Raw
if ($envText -match "(?m)^MT5_PASSWORD=") {
  $envText = [regex]::Replace($envText, "(?m)^MT5_PASSWORD=.*$", "MT5_PASSWORD=$plainPassword")
} else {
  $envText = $envText.TrimEnd() + [Environment]::NewLine + "MT5_PASSWORD=$plainPassword" + [Environment]::NewLine
}

[System.IO.File]::WriteAllText((Resolve-Path $envPath), $envText)
Write-Output "MT5_PASSWORD_UPDATED"