private static void OnBoundPasswordChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { PasswordBox box = d as PasswordBox; // only handle this event when the property is attached to a PasswordBox // and when the BindPassword attached property has been set to true if (d == null || !GetBindPassword(d)) { return; } // avoid recursive updating by ignoring the box's changed event box.PasswordChanged -= HandlePasswordChanged; string newPassword = (string)e.NewValue; newPassword = KfEncryption.DecryptString(newPassword).ToInsecureString(); if (!GetUpdatingPassword(box)) { box.Password = newPassword; } box.PasswordChanged += HandlePasswordChanged; }
public void Login(Action <LoginStatus> loggedIn) { if (LoginStatus == LoginStatus.None) { // set up the listeners for SIGNIN api.SignInFailed += (sender, e) => { LogError(Resources.SignInFailed, e); LoginStatus = LoginStatus.Failed; loggedIn(LoginStatus); }; api.SignInComplete += (sender, result) => { LogInfo(Resources.SignedIn); LoginStatus = LoginStatus.Successful; cookie = result.CookieHeaders; loggedIn(LoginStatus); }; if (!string.IsNullOrEmpty(Settings.Default.Username) && !string.IsNullOrEmpty(Settings.Default.Password)) { api.SignIn(Settings.Default.Username, KfEncryption.DecryptString(Settings.Default.Password).ToInsecureString()); } else { // no account set LoginStatus = LoginStatus.Anonymous; loggedIn(LoginStatus); } } else { loggedIn(LoginStatus); } }
public static void SetBoundPassword(DependencyObject dp, string value) { dp.SetValue(BoundPassword, KfEncryption.EncryptString(value)); }