示例#1
0
        public static Results AddPassword(Password pwd)
        {
            Results results = null;
            if(pwd != null)
            {
                try
                {
                    // Have a rollback mechanism so that if any of the storage fails then we rollback.
                    var pair = CreateKeyValuePair(pwd);
                    bool foundValue = false;

                    if (tempPassword != null)
                    {
                        foundValue = localStorage.Values.ContainsKey(tempPassword.Key);
                    }

                    if (foundValue)
                    {
                        localStorage.Values.Remove(tempPassword.Key);
                    }

                    localStorage.Values.Add(pair);

                    if (Helper.IsInternet)
                    {
                        foundValue = false;

                        if (tempPassword != null)
                        {
                            foundValue = cloudStorage.Values.ContainsKey(tempPassword.Key);
                        }

                        if (foundValue)
                        {
                            cloudStorage.Values.Remove(tempPassword.Key);
                        }

                        cloudStorage.Values.Add(pair);
                    }

                    if (cachedPasswordList.Contains(tempPassword))
                    {
                        cachedPasswordList.Remove(tempPassword);
                    }

                    cachedPasswordList.Add(pwd);
                }
                catch(Exception exception)
                {
                    results = new Results{Message = "Error Adding the password: "+ exception.Message, ResultsType = ResultsType.Error};
                }
            }

            return results ?? new Results {Message = null, ResultsType = ResultsType.Success};
        }
示例#2
0
        private void ShowPasswordModal(Password selectedPassword)
        {
            if (selectedPassword != null)
            {
                //Display the password

                TitleTextBox.Text = selectedPassword.Title;
                UserNameTextBox.Text = selectedPassword.UserName;
                PasswordTextBox.Text = selectedPassword.PasswordText;

                TitleTextBox.IsEnabled = UserNameTextBox.IsEnabled = false;
                PasswordTextBox.Visibility = Visibility.Visible;
                PasswordBox.Visibility = Visibility.Collapsed;

                DeleteButton.Visibility = CancelButton.Visibility = SaveButton.Visibility = Visibility.Collapsed;
                EditButton.Visibility = Visibility.Visible;

                Storage.tempPassword = selectedPassword;
            }
            else
            {
                TitleTextBox.Text = UserNameTextBox.Text = PasswordTextBox.Text = string.Empty;

                TitleTextBox.IsEnabled = UserNameTextBox.IsEnabled = true;
                DeleteButton.Visibility = EditButton.Visibility = PasswordTextBox.Visibility = Visibility.Collapsed;
                SaveButton.Visibility = PasswordBox.Visibility = Visibility.Visible;

                this.TitleTextBox.Focus(FocusState.Keyboard);
            }

            this.PasswordModal.Visibility = Visibility.Visible;

            var bottomAppBar = this.BottomAppBar;
            if (bottomAppBar != null) bottomAppBar.IsOpen = false;
        }
示例#3
0
        /// <summary>
        /// Takes the users input and save the password
        /// </summary>
        /// <param name="sender"> The sender. </param>
        /// <param name="e"> The e. </param>
        private void AddPasswordClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(TitleTextBox.Text))
            {
                TitleBorder.BorderThickness = new Thickness(4);
                return;
            }

            TitleBorder.BorderThickness = new Thickness(0);

            var passwordToBeSaved = new Password
            {
                UserName = this.UserNameTextBox.Text,
                Title = this.TitleTextBox.Text,
                Key = this.TitleTextBox.Text,
                PasswordText = this.PasswordBox.Password
            };

            Results addPasswordResults = Storage.AddPassword(passwordToBeSaved);

            if (addPasswordResults.ResultsType == ResultsType.Error)
            {
                MessageDialog messagebox = new MessageDialog(addPasswordResults.Message, "Cannot add the Password");
                messagebox.ShowAsync();
                Debug.WriteLine(addPasswordResults.Message);
            }
            else
            {
                this.TitleTextBox.Text = this.UserNameTextBox.Text = this.PasswordBox.Password = string.Empty;
                this.PasswordModal.Visibility = Visibility.Collapsed;

                this.RefreshScreen();
            }
        }
示例#4
0
 private static KeyValuePair<string, object> CreateKeyValuePair(Password password)
 {
     return new KeyValuePair<string, object>(password.Key, JsonConvert.SerializeObject(password));
 }
示例#5
0
        public static void DeletePassword(Password pwd)
        {
            if (pwd != null)
            {
                Debug.WriteLine("Delete is going to match on the following key : " + (pwd.KeyGuid.Equals(Guid.Empty) ? pwd.Title : pwd.KeyGuid.ToString()));

                cachedPasswordList.Remove(pwd);

                localStorage.Values.Remove(CreateKeyValuePair(pwd));
            }
            else
            {
                Debug.WriteLine("selected item was not a Password object");
            }
        }