Hi there,
I have come across a problem with binding to a passwordbox. It seems its a security risk but i am using the MVVM pattern so i wish to bypass this. I found some interesting code here (has anyone used this? or something similar?)
http://www.wpftutorial.net/PasswordBox.html
It technically looks great, but i am unsure how to retrieve the password.
I basically have a property in my LoginViewModel for Username and Password, of course username is fine and is working as its a textbox..
I used the code above as stated and entered this
<PasswordBox ff:PasswordHelper.Attach="True"
ff:PasswordHelper.Password="{Binding Path=Password}" Width="130"/>
As you can see i am binding to Password, but maybe its bind it to the static class..
Still a beginner here so i am really confused.
When i had the passwordbox as a textbox and Binding path=Password then the property in my LoginViewModel was updated.
Can anyone lend a hand or provide a better alternative?
My code is very simple, basically i have a command for my button that when i press it arrives and checks CanLogin (you can see i check my property for username here which works great) and if it returns true it calls Login..
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;
public string Username { get; set; }
public string Password { get; set; }
public ICommand LoginCommand
{
get
{
if (loginCommand == null)
{
loginCommand = new DelegateCommand(
Login, CanLogin );
}
return loginCommand;
}
}
private bool CanLogin()
{
return !string.IsNullOrEmpty(Username);
}
private void Login()
{
bool result = securityService.IsValidLogin(Username, Password);
if (result)
{
}
else
{
}
}