C# 如何从 PasswordBox 获取文本值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2327234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# how to get text value from PasswordBox?
提问by 5YrsLaterDBA
I have a PasswordBox
. how can I get the input value from the PasswordBox
after the input has been finished?
我有一个PasswordBox
. PasswordBox
输入完成后如何获取输入值?
采纳答案by Klaus Byskov Pedersen
You can get it from the Password
property.
您可以从Password
酒店获得。
回答by Roast
If using a MaskedTextbox you can use the .text property. For example:
如果使用 MaskedTextbox,您可以使用 .text 属性。例如:
private void btnOk_Click(object sender, EventArgs e)
{
if ( myMaskedTextbox.Text.Equals(PASSWORD) )
{
//do something
}
}
回答by Ehtesham
I use below code to get the length of PasswordBox
我使用下面的代码来获取 PasswordBox 的长度
PasswordVariableName.Password.Length
It will certainly work on wp8
它肯定适用于 wp8
回答by Death Zone
You may extract it from Password
property:
您可以从Password
属性中提取它:
passwordBox.Password.ToString()
回答by jiciftw
You may not want to store the password in clear text in memory, from the msdn doc you should use SecurePassword in order to prevent that.
您可能不想将密码以明文形式存储在内存中,从 msdn 文档中,您应该使用 SecurePassword 来防止这种情况。
Example: SecureString myPass = passwordBox.SecurePassword
例子: SecureString myPass = passwordBox.SecurePassword
https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.passwordbox.securepassword
https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.passwordbox.securepassword