In WPF the PasswordBox control doesn’t expose any property to bind it. You’ll need solutions as described here to get the password the ‘WPF way’. Getting it to validate is a different story.
Whenever a user is created you want the password to be confirmed. That was, is and allways will be the way to make sure the user knows the password. Mistakes are quickly made and this way the mistake has to be made twice before it becomes a problem. But how to compare two PasswordBox controls that use the passwordhelper?
Use the IDataErrorInfo to implement your own validation. A sample implementation is below. Ignore the Error property of the interface as we don’t use it in this implementation.
public string this[string columnName] { get { string result = null; // columName is the name of the property whose error message to get switch (columnName) { case "PasswordConfirm": // only check if password is supplied, else confirm is obsolete // password must be equal to confirm if (string.IsNullOrEmpty(Password) == false && Password.Equals(PasswordConfirm) == false) { result = "Passwords differ"; } break; } return result; } }
A complete sample is available for download here.
sadly, that doesn’t cover when the password itself is changed and the password confirmation was matching the password before…