Powershell GUI,如何在不暴露的情况下获取密码输入

huangapple go评论60阅读模式
英文:

Powershell GUI, How to take password input without exposing

问题

我有一个情况,我正在编写一个PowerShell图形界面。

我需要以安全的方式获取密码输入... 我该如何做?

密码输入需要在窗口中保护。

下面是我的代码:

$Passwd                         = New-Object system.Windows.Forms.TextBox
$Passwd.multiline               = $false
$Passwd.width                   = 150
$Passwd.height                  = 20
$Passwd.location                = New-Object System.Drawing.Point(169,26)
$Passwd.Font                    = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$Passwd.ForeColor               = [System.Drawing.ColorTranslator]::FromHtml("#7ed321")
$Passwd.BackColor               = [System.Drawing.ColorTranslator]::FromHtml("#000000")

这是代码。

密码输入需要保持安全吗?

英文:

I have a situation I am writing a powershell GUI.

I need to take the password in a secure input.. How can I do it ?

The passwd input need to be secured in the window

below is my code


$Passwd                         = New-Object system.Windows.Forms.TextBox
$Passwd.multiline               = $false
$Passwd.width                   = 150
$Passwd.height                  = 20
$Passwd.location                = New-Object System.Drawing.Point(169,26)
$Passwd.Font                    = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$Passwd.ForeColor               = [System.Drawing.ColorTranslator]::FromHtml("#7ed321")
$Passwd.BackColor               = [System.Drawing.ColorTranslator]::FromHtml("#000000")

this is the code

the passwd input nee to be secured input ?

答案1

得分: 0

需要将UseSystemPasswordChar 设置为 $true

$Passwd.UseSystemPasswordChar = $true
英文:

You need to set UseSystemPasswordChar to $true:

$Passwd.UseSystemPasswordChar = $true

答案2

得分: 0

我尝试了system.Windows.Forms.TextBox,它有效。

英文:

I tried system.Windows.Forms.TextBox, it worked.

$Passwd                         = New-Object system.Windows.Forms.TextBox

huangapple
  • 本文由 发表于 2023年6月2日 12:41:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76387153.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定