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 ($Value) { return $Value }
|
||||||
if ($Secure) {
|
if ($Secure) {
|
||||||
$secure = Read-Host -Prompt $Prompt -AsSecureString
|
$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)
|
$ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)
|
||||||
try { return [Runtime.InteropServices.Marshal]::PtrToStringUni($ptr) }
|
try { return [Runtime.InteropServices.Marshal]::PtrToStringUni($ptr) }
|
||||||
finally {
|
finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user