/// <summary> /// Adds a new password to the password store. /// </summary> public void AddPassword() { Helpers.AssertOnUiThread(); var passwordFilePath = ShowFileSelectionWindow(); // passwordFileName will be null if no file was selected if (passwordFilePath == null) { return; } // Display the password generation window. string password; string metadata; using (var passwordWindow = new PasswordWindow(Path.GetFileName(passwordFilePath), ConfigManager.Config.PasswordStore.PasswordGeneration)) { passwordWindow.ShowDialog(); if (!passwordWindow.DialogResult.GetValueOrDefault()) { return; } password = passwordWindow.Password.Text; metadata = passwordWindow.ExtraContent.Text.Replace(Environment.NewLine, "\n"); } PasswordFile passwordFile; try { passwordFile = passwordManager.AddPassword(passwordFilePath, password, metadata); } catch (GpgException e) { notificationService.ShowErrorWindow("Unable to encrypt your password: "******"Unable to encrypt your password: "******"The new password has been copied to your clipboard.\nIt will be cleared in {ConfigManager.Config.Interface.ClipboardTimeout:0.##} seconds.", Severity.Info); } // Add the password to Git syncService?.AddPassword(passwordFile.FullPath); }
public void Confirm() { //Call Notes Dependency and add to the Collection of Notes, along to the database try { if (string.IsNullOrWhiteSpace(Description)) { throw new ArgumentNullException("Description cannot be empty"); } if (string.IsNullOrWhiteSpace(Password)) { throw new ArgumentNullException("Password cannot be empty"); } if (!string.IsNullOrWhiteSpace(Constants.Passwords_ID)) { var password = _passwordManager.Get_PasswordByID <Passwords>(Constants.Passwords_ID); if (password != null) { password.Password = Password; password.Description = Description; _passwordManager.UpdatePassword(password); MessagingCenter.Send <PasswordCreatorViewModel, Passwords>(this, _UpdatePassword, password); } else { var obj = new Passwords(); obj.Contact_ID_Ref = Constants.InMemory_ContactID; obj.Password_ID = _passwordManager.Get_NewPasswordID(); obj.Description = Description; obj.Password = Password; obj.Sys_Creation = DateTime.Now; obj.Sys_Transaction = DateTime.Now; _passwordManager.AddPassword(obj); MessagingCenter.Send <PasswordCreatorViewModel, Passwords>(this, _AddPassword, obj); } } else { var obj = new Passwords(); obj.Contact_ID_Ref = Constants.InMemory_ContactID; obj.Password_ID = _passwordManager.Get_NewPasswordID(); obj.Description = Description; obj.Password = Password; obj.Sys_Creation = DateTime.Now; obj.Sys_Transaction = DateTime.Now; _passwordManager.AddPassword(obj); MessagingCenter.Send <PasswordCreatorViewModel, Passwords>(this, _AddPassword, obj); } //Pop to previous page if (navigation != null) { navigation.GoBackAsync(true); } } catch (Exception ex) { string eMessage = string.Empty; string eStackTrace = string.Empty; if (ex.InnerException != null) { eMessage = ex.InnerException.Message; eStackTrace = ex.InnerException.StackTrace; } else { eMessage = ex.Message; eStackTrace = ex.StackTrace; } var mEx = new Exceptions(logging, eMessage, eStackTrace); if (mEx != null) { mEx.HandleException(mEx, logging); } //Output a dialogue here if (dialogue != null && mEx != null) { dialogue.ShowAlert("mmm...Something went wrong", mEx.Message); } } }