wpf password box into a SecureString in C#

前端 未结 3 1975
一整个雨季
一整个雨季 2021-01-05 20:38

I am attempting to get the data from a wpf password box into a secure string. How is that done? what i have so far:

 SecureString pass = new SecureString();         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-05 21:24

    you need to read each character in

    SecureString pass = new SecureString();
    
    foreach (char c in pbox1.Password)
    {
      pass.AppendChar(c);
    }
    

    or more securely use the SecurePassword property

    SecureString pass = pbox1.SecurePassword
    

提交回复
热议问题