bionmaple.blogg.se

Passwordbox alternative
Passwordbox alternative













passwordbox alternative
  1. Passwordbox alternative update#
  2. Passwordbox alternative code#
  3. Passwordbox alternative password#

(which might be violated slightly by the "attached property"

passwordbox alternative

Unnecessary complexity is also one of those "best practice" rules

Passwordbox alternative code#

  • writing simple, easy-to-read, maintainable code and avoiding.
  • best practices are "recommendations that work well in most cases".
  • Yes, you are violating ViewModel best practices here, but Executed when the Login button is clicked. NET documentation explains why the PasswordBox was not made bindable in the first place.Īn alternative solution is to put the PasswordBox in your ViewModelpublic class LoginViewModel public class LoginViewModel SecurePassword cannot be done with bindings.

    Passwordbox alternative password#

    Keeping your password in plain text on the client machine RAM is a security no-no. I would suggest that when accessing the PasswordBox.Password CLR property you'd refrain from placing it in any variable or as a value for any property. The PasswordBox uses encrypted memory (of sorts) and the only way to access the password is through the CLR property. Which is considered quite a troublesome security attack vector. If WPF/Silverlight were to keep a DP for Password it would require the framework to keep the password itself unencrypted in memory. The reason the WPF/Silverlight PasswordBox doesn't expose a DP for the Password property is security related. You probably don't want to do this anyway but if you really want to go ahead. Private static void SetUpdatingPassword(DependencyObject dp, bool value) Return (bool)dp.GetValue(UpdatingPassword) Private static bool GetUpdatingPassword(DependencyObject dp) Public static void SetBoundPassword(DependencyObject dp, string value) Return (string)dp.GetValue(BoundPassword) Public static string GetBoundPassword(DependencyObject dp) Public static bool GetBindPassword(DependencyObject dp) Public static void SetBindPassword(DependencyObject dp, bool value) push the new password into the BoundPassword property set a flag to indicate that we're updating the password Private static void HandlePasswordChanged(object sender, RoutedEventArgs e) start listening to its PasswordChanged event when the BindPassword attached property is set on a PasswordBox, Private static void OnBindPasswordChanged(DependencyObject dp, DependencyPropert圜hangedEventArgs e) avoid recursive updating by ignoring the box's changed eventīox.PasswordChanged -= HandlePasswordChanged īox.PasswordChanged += HandlePasswordChanged and when the BindPassword attached property has been set to true only handle this event when the property is attached to a PasswordBox Private static void OnBoundPasswordChanged(DependencyObject d, DependencyPropert圜hangedEventArgs e) Private static readonly DependencyProperty UpdatingPassword =ĭependencyProperty.RegisterAttached("UpdatingPassword", typeof(bool), typeof(PasswordBoxAssistant), new PropertyMetadata(false)) "BindPassword", typeof (bool), typeof (PasswordBoxAssistant), new PropertyMetadata(false, OnBindPasswordChanged)) Public static readonly DependencyProperty BindPassword = DependencyProperty.RegisterAttached( Public static readonly DependencyProperty BoundPassword =ĭependencyProperty.RegisterAttached("BoundPassword", typeof(string), typeof(PasswordBoxAssistant), new PropertyMetadata(string.Empty, OnBoundPasswordChanged))

    Passwordbox alternative update#

    What actually doesn't work is, that the TargetPassword property doesn't update the property of my ViewModelĬreate an attach property public static class PasswordBoxAssistant I hope anyone can help, atm I use the codebehind version but I rather wouldn't. Public static readonly DependencyProperty TargetPasswordProperty = DependencyProperty.Register("TargetPassword", typeof(SecureString), typeof(PasswordChangedBehavior), new PropertyMetadata(default(SecureString))) Īnd last, the part of my ViewModel. This enables animation, styling, binding, etc. Using a DependencyProperty as the backing store for TargetPassword. Public class PasswordChangedBehavior : Behavior But would be nice if someone would post ideas or sth. PS: I am currently on the way home without my laptop, I gonna update the question with my code in about 15 minutes. Sadly it doesn't work properly.īasically I added a property to the Behavior which contains the target property of my ViewModel. I try to bind the SecurePassword property of a PasswordBox to my ViewModel with a custom Behavior.















    Passwordbox alternative