Put SecureString into PasswordBox

时光怂恿深爱的人放手 提交于 2020-01-02 02:17:08

问题


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:


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.



来源:https://stackoverflow.com/questions/19747195/put-securestring-into-passwordbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!