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.
This commit is contained in:
2026-08-30 21:26:13 -05:00
parent 1965e07c7c
commit c3ad14cb88
+42 -2
View File
@@ -415,8 +415,48 @@ if (-not $connected -and (Test-Path $logFile)) {
Write-Host "" Write-Host ""
Write-Host ("=" * 64) -ForegroundColor Cyan Write-Host ("=" * 64) -ForegroundColor Cyan
if ($connected) { if ($connected) {
Write-Host " Login works. The account is fine - so if a script using these" -ForegroundColor Green Write-Host " Login works. These details are correct." -ForegroundColor Green
Write-Host " same details still fails, the script is mangling one of them." -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 { } else {
Write-Host " Login failed. Compare against the WinSCP window: File > Session" -ForegroundColor Yellow 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 Write-Host " > Generate Session URL/Code > .NET assembly code. That shows the" -ForegroundColor Yellow