title: Is it a bad idea to bind PasswordBox password?
body: <p>I've read that the password in a WPF PasswordBox does not have a dependency property for binding the password <em>for security reasons</em>. Despite this, there are <a href="http://wpftutorial.net/PasswordBox.html" rel="nofollow noreferrer">ways to bind it anyway</a>.</p>
  
  <p>Users of the MVVM pattern require this databinding; the viewmodel cannot touch the PasswordBox directly without breaking the pattern. One way to work with PasswordBoxes in an MVVM setting is to <a href="https://stackoverflow.com/a/15391318/983064">pass the entire PasswordBox control</a> to the ViewModel, but this breaks the pattern anyway. Binding the Password is probably the cleanest way to work with passwords using MVVM.</p>
  
  <p>There is an <a href="https://stackoverflow.com/questions/1483892/how-to-bind-to-a-passwordbox-in-mvvm/1493330#1493330">argument against binding the Password</a> since this would keep the plaintext password in unencrypted memory until it gets garbage collected. The way I see it, however, is that the password gets stored in unencrypted memory anyway from the moment you access the <code>Password</code> property. This view (or similar) seems to be seconded in <a href="https://stackoverflow.com/questions/22511656/safety-benefits-of-the-password-in-wpf-passwordbox-not-being-bindable">this question</a>. Of course it would be in memory for a shorter period without binding (not that login forms have a tendency of being long-lived anyway), but the risk is still there.</p>
  
  <p>Given these arguments, is it really a bad idea to bind the password? And why?</p>