Harden password prompt against non-secure values
This commit is contained in:
@@ -51,6 +51,9 @@ function Read-PlainOrPrompt([string]$Value, [string]$Prompt, [bool]$Secure = $fa
|
||||
if ($Value) { return $Value }
|
||||
if ($Secure) {
|
||||
$secure = Read-Host -Prompt $Prompt -AsSecureString
|
||||
if (-not ($secure -is [System.Security.SecureString])) {
|
||||
$secure = ConvertTo-SecureString -String ([string]$secure) -AsPlainText -Force
|
||||
}
|
||||
$ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)
|
||||
try { return [Runtime.InteropServices.Marshal]::PtrToStringUni($ptr) }
|
||||
finally {
|
||||
|
||||
Reference in New Issue
Block a user