[英]How to mask user input password in parameter of C# custom Cmdlet
In my program I need to ask user for password in parameter: 在我的程序中,我需要在参数中要求用户输入密码:
[Cmdlet(VerbsCommon.Get, "MyTest"]
public class GetMyTest : PSCmdlet
{
[Parameter(Mandatory=true)]
public ? Password { get; set;}
}
I can't figure out what is the correct type to use for Password. 我不知道密码使用的正确类型是什么。 In another question: How does one securely handle passwords in a custom written PowerShell cmdlet?
另一个问题是: 如何在自定义的书面PowerShell cmdlet中安全地处理密码?
The accepted answer asked to use read-host in the code, but I have to use parameter to ask for this field. 可接受的答案要求在代码中使用读取主机,但是我必须使用参数来询问此字段。
I also tried to use SecureString for Password, but I am not able to give a SecureString to this parameter as it will be automatically accepted as string, not secure string. 我也尝试将SecureString用于密码,但是我无法为该参数提供SecureString,因为它将被自动接受为字符串,而不是安全字符串。
Is it any way to achieve the following usage: 是否可以实现以下用法:
Get-MyTest -Password ***** (where I actually type in 'abcde' but the input is masked.)
Usually what is done is that you store the password in a string-typed variable and then you hash it somehow (SHA256, MD5, or so) to store it in the database (or to compare it and allow or not user to access the application. 通常要做的是将密码存储在字符串类型的变量中,然后以某种方式对其进行哈希处理(SHA256,MD5等)以将其存储在数据库中(或进行比较以允许或不允许用户访问应用程序) 。
So, I am not sure there is a better type for that. 因此,我不确定是否有更好的类型。
There is no way to make particular portion of command line input to be protected with asterisks - command line input is just plain text. 无法使用星号来保护命令行输入的特定部分-命令行输入只是纯文本。
Options 选项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.