From c3ad14cb88609c80849d6afe4ff21c239b317a73 Mon Sep 17 00:00:00 2001 From: Brad Lance Date: Sun, 30 Aug 2026 21:26:13 -0500 Subject: [PATCH] Print the exact quoted literal after a successful login The decoded password works and contains a $, so the original suspicion was right about the upload script even though it was wrong about this test - typing into a prompt never involved a string literal. On success the test now prints the line to paste, apostrophes doubled and single quotes included, and explains why: inside double quotes PowerShell reads $Pass2026 as a variable and sends a shorter string, so a correct password still fails. It also flags % for .bat files and suggests keeping the password in its own file, where no quoting applies. Checked against a $ password, an embedded apostrophe, a %, and a plain one that correctly draws no advice at all. --- Test-Login.ps1 | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/Test-Login.ps1 b/Test-Login.ps1 index f0457d1..2f95897 100644 --- a/Test-Login.ps1 +++ b/Test-Login.ps1 @@ -415,8 +415,48 @@ if (-not $connected -and (Test-Path $logFile)) { Write-Host "" Write-Host ("=" * 64) -ForegroundColor Cyan if ($connected) { - Write-Host " Login works. The account is fine - so if a script using these" -ForegroundColor Green - Write-Host " same details still fails, the script is mangling one of them." -ForegroundColor Green + Write-Host " Login works. These details are correct." -ForegroundColor Green + Write-Host ("=" * 64) -ForegroundColor Cyan + + # Getting a working password into a script is its own trap, so hand back + # the literal to paste rather than leaving the quoting to chance. + $needsCare = $password -match '[\$`]' + if ($needsCare -or $password -match "'" -or $password -match '%') { + Write-Host "" + Write-Host " Putting this password into a PowerShell script" -ForegroundColor Cyan + Write-Host (" " + ("-" * 60)) -ForegroundColor Cyan + Write-Host "" + Write-Host " Use exactly this line, single quotes included:" -ForegroundColor White + Write-Host "" + Write-Host " `$Password = $("'" + ($password -replace "'", "''") + "'")" -ForegroundColor Green + Write-Host "" + if ($needsCare) { + Write-Host " This password contains a `$ or a backtick. Inside DOUBLE" -ForegroundColor Yellow + Write-Host " quotes PowerShell treats that as a variable and silently" -ForegroundColor Yellow + Write-Host " sends something shorter - the login then fails even though" -ForegroundColor Yellow + Write-Host " the password is right. Single quotes send it untouched." -ForegroundColor Yellow + } + if ($password -match "'") { + Write-Host " The password contains an apostrophe, so it is doubled in" -ForegroundColor Yellow + Write-Host " the line above. That is correct - it stays one character." -ForegroundColor Yellow + } + if ($password -match '%') { + Write-Host " The password contains a %. That is fine in PowerShell, but" -ForegroundColor Yellow + Write-Host " in a .bat file it must be written as %% instead." -ForegroundColor Yellow + } + Write-Host "" + Write-Host " Safer still: keep it out of the script. Put the password on" -ForegroundColor Gray + Write-Host " the first line of its own file and read it back - then no" -ForegroundColor Gray + Write-Host " quoting rules apply to it at all:" -ForegroundColor Gray + Write-Host ' $Password = Get-Content pw.txt -TotalCount 1' -ForegroundColor Gray + } else { + Write-Host "" + Write-Host " Nothing in this password needs special quoting in a script." -ForegroundColor Green + } + Write-Host "" + Write-Host ("=" * 64) -ForegroundColor Cyan + Write-Host " If a script using these same details still fails, the script is" -ForegroundColor Green + Write-Host " changing one of them on the way through." -ForegroundColor Green } else { Write-Host " Login failed. Compare against the WinSCP window: File > Session" -ForegroundColor Yellow Write-Host " > Generate Session URL/Code > .NET assembly code. That shows the" -ForegroundColor Yellow