C# how to get text value from PasswordBox?

2020-02-09 23:30发布

I have a PasswordBox. how can I get the input value from the PasswordBox after the input has been finished?

5条回答
我欲成王,谁敢阻挡
2楼-- · 2020-02-10 00:11

I use below code to get the length of PasswordBox

PasswordVariableName.Password.Length

It will certainly work on wp8

查看更多
beautiful°
3楼-- · 2020-02-10 00:14

You may extract it from Password property:

passwordBox.Password.ToString()
查看更多
成全新的幸福
4楼-- · 2020-02-10 00:31

You can get it from the Password property.

查看更多
爷、活的狠高调
5楼-- · 2020-02-10 00:31

If using a MaskedTextbox you can use the .text property. For example:

private void btnOk_Click(object sender, EventArgs e)
{
    if ( myMaskedTextbox.Text.Equals(PASSWORD) )
    {
        //do something
    }         

}
查看更多
仙女界的扛把子
6楼-- · 2020-02-10 00:34

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.

Example: SecureString myPass = passwordBox.SecurePassword

https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.passwordbox.securepassword

查看更多
登录 后发表回答