easyrefa.blogg.se

Passwordbox helper
Passwordbox helper







  1. #Passwordbox helper how to
  2. #Passwordbox helper code

Private static void SetUpdatingPassword(DependencyObject dp, bool value)ĭp.SetValue(UpdatingPasswordProperty, value) Return (bool)dp.GetValue(UpdatingPasswordProperty) Private static bool GetUpdatingPassword(DependencyObject dp) Public static void SetBindablePassword(DependencyObject dp, SecureString value)ĭp.SetValue(BindablePasswordProperty, value) Return (string)dp.GetValue(BindablePasswordProperty) Public static string GetBindablePassword(DependencyObject dp) Return (bool)dp.GetValue(BindPasswordProperty) Public static bool GetBindPassword(DependencyObject dp) Public static void SetBindPassword(DependencyObject dp, bool value)ĭp.SetValue(BindPasswordProperty, value) Private static readonly DependencyProperty UpdatingPasswordProperty =ĭependencyProperty.RegisterAttached("UpdatingPassword", typeof(bool), Typeof(bool), typeof(PasswordHelper), new PropertyMetadata(false, BindPassword)) Public static readonly DependencyProperty BindPasswordProperty =ĭependencyProperty.RegisterAttached("BindPassword", New FrameworkPropertyMetadata(string.Empty, OnPasswordPropert圜hanged)) Typeof(SecureString), typeof(PasswordHelper), Public static readonly DependencyProperty BindablePasswordProperty =ĭependencyProperty.RegisterAttached("BindablePassword", These all have been implemented to tackle the security issues with implementing dependency property as String. I have modified the PasswordHelper class to incorporate following :-ġ) Implementation of SecureString type for dependency property instead of String.Ģ) Binding SecureString type property from ViewModel to PasswordBox's SecurePassword property instead of Password property.ģ) Utility method to convert from SecureString to String and vice versa. Below is sample of PasswordHelper class that extends the PasswordBox and provide dependency property BindablePassword for binding. What I found well suited in accordance with the MVVM implementation is having attached property extend the PasswordBox and provide much needed dependency property for binding. You can find the discussion and solutions in below thread :.

#Passwordbox helper code

Now there are many solutions and workarounds like having event in ViewModel that is registerd in view and acts as the password catcher, passing whole PasswordBox to ViewModel in command paramter of login button Command, having content control binding to the property in ViewModel of type PasswordBox, handling password change in code behind and creating PasswordBoxHelper attached behaviour etc.

passwordbox helper passwordbox helper

This problem stems from the fact that Password property of the PasswordBox is not a dependency property for obvious security reasons, hence we cant bind it as we would normally do.

passwordbox helper

#Passwordbox helper how to

Problem statement is how to bind Password property of PasswordBox to a property in a ViewModel. PasswordBox implementation using MVVM is one of the widly debated topic around MVVM arena.









Passwordbox helper