
The best one yet is to stick to a custom attached property and bind to your SecureString property in your view model.
#Passwordbox download code
I didn't like the decorators idea, behaviors mess up the validation UI, code behind. I spent a great deal of time looking at various solutions.
#Passwordbox download password
When a server request requiring your password is taking place, call your IoC for the IHavePassword implementation and only than get the much coveted password. Register the UserControl instance with your IoC as implementing the IHavePassword interface.Ĥ. Have your UserControl implement a IHavePassword interface.ģ. Create the IHavePassword interface with one method that returns the password clear text.Ģ. If you're looking for an over-architected solution, here's one:ġ. I know this breaks the MVVM pattern, but you shouldn't ever bind to PasswordBox.Password Attached DP, store your password in the ViewModel or any other similar shenanigans. Don't keep clear text passwords in memory.

When accessing PasswordBox.Password, just get it out and ship it to the server ASAP.ĭon't keep the value of the password around and don't treat it as you would any other client machine text. public SecureString SecurePassword you've got up there. Note that it is a SecureString, not just a string. I made it "write only" since there shouldn't be a need to retrieve it from outside the ViewModel for any reason, but it doesn't have to be. In the ViewModel, just a simple property. In this case, we are just manually coding a binding, so its all considered part of the UI implementation and therefore is ok. The ViewModel still has no knowledge of the View implementation, which in my mind it does if you are trying to pass the PasswordBox in to the ViewModel.Ĭode Behind != Automatic MVVM violation. Yes, technically it is code behind, but it is nothing more than a "special case" binding. This method does not violate the MVVM pattern and maintains complete security. Maybe I am missing something, but it seems like most of these solutions overcomplicate things and do away with secure practices. I put a breakpoint and sure enough the code enter the static helper class but it never updates my Password in my ViewModel. I have my TextBox, this is no problem, but in my ViewModel the Password is empty.Īm I doing something wrong or missing a step? In Login I send along to my service a Username and Password, Username contains data from my View but Password is Null|Empty private DelegateCommand loginCommand īool result = securityService.IsValidLogin(Username, Password) You can see I check my property for Username here which works great. When I press it CanLogin is called and if it returns true it calls Login. My code is very simple, basically I have a Command for my Button. When I had the PasswordBox as a TextBox and Binding Path=Password then the property in my LoginViewModel was updated.

I used the code above as stated and entered this Username is fine and is working as it's a TextBox.

I basically have properties in my LoginViewModel for Username and Password.
#Passwordbox download how to
It technically looks great, but I am unsure of how to retrieve the password.

I found some interesting code here (has anyone used this or something similar?) It seems it's a security risk but I am using the MVVM pattern so I wish to bypass this. I have come across a problem with binding to a PasswordBox.
