Put SecureString into PasswordBox

2019-04-22 05:59发布

I have an existing SecureString that I would like to put into a PasswordBox without revealing the .Password. Can this be done? For example:

tbPassword.SecurePassword = DecryptString(Properties.Settings.Default.proxyPassword);

In this case DecryptString produces a SecureString. However, SecurePassword is a read-only property so I can't assign a value to it.

1条回答
爷、活的狠高调
2楼-- · 2019-04-22 06:30

You can't.

However, what you can do is put placeholder text in it's place (it can even be "placeholder", we are only using it to make a few dots to show up in the box).

After you put the placeholder in, when you go to retrieve the "current password" somewhere in your program first check if the PasswordChanged event has fired since you entered the placeholder password. If the event has not fired use the old stored password, if the event has fired use the current password from the SecurePassword property of PasswordBox.

查看更多
登录 后发表回答