/// <summary> /// store the password with the according method /// </summary> /// <param name="_pw"></param> private void storePassword(String _pw) { #if WIN32 && DPAPI DPAPIUtil.storePassword(_pw); #else Preferences.Set(AddinPreferences.SYNC_PRIVATENOTES_PASSWORD, _pw); #endif }
/// <summary> /// setup fields like: store password:yes/no and the actual password entry, /// if it should be stored /// </summary> /// <param name="insertTo"></param> /// <param name="defaultSpacing"></param> void SetupGuiEncryptionRelated(Gtk.Box insertTo, int defaultSpacing) { Gtk.HBox customBox = new Gtk.HBox(false, defaultSpacing); insertTo.PackStart(customBox); rbt_storePw = new Gtk.RadioButton(Catalog.GetString("_Store password")); customBox.PackStart(rbt_storePw); customBox = new Gtk.HBox(false, defaultSpacing); insertTo.PackStart(customBox); // --- Password Boxes --- #if WIN32 && DPAPI String pw = DPAPIUtil.getPassword(); #else String pw = Convert.ToString(Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_PASSWORD)); #endif pw = (pw == null) ? "" : pw; Gtk.VBox pwbox = new Gtk.VBox(false, defaultSpacing); Gtk.HBox superbox = new Gtk.HBox(false, defaultSpacing); superbox.PackStart(new Gtk.Alignment(0, 0, 200, 0)); // spacer superbox.PackStart(pwbox); customBox.PackStart(superbox); stored_pw = new Gtk.Entry(); // set password style: stored_pw.InvisibleChar = '*'; stored_pw.Visibility = false; stored_pw.Text = pw; pwbox.PackStart(stored_pw); stored_pw2 = new Gtk.Entry(); // set password style: stored_pw2.InvisibleChar = '*'; stored_pw2.Visibility = false; stored_pw2.Text = pw; pwbox.PackStart(stored_pw2); match_label = new Gtk.Label(); match_label.Markup = Catalog.GetString(AddinPreferences.MATCH_TEXT); pwbox.PackStart(match_label); customBox = new Gtk.HBox(false, defaultSpacing); insertTo.PackStart(customBox); // give the first rbt here to link the 2 rbt_alwaysAsk = new Gtk.RadioButton(rbt_storePw, Catalog.GetString("_Always ask for password")); customBox.PackStart(rbt_alwaysAsk); // assign event-listener rbt_storePw.Toggled += PasswordMethodChanged; // init with values from preferences object value = Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_ASKEVERYTIME); if (value == null || value.Equals(false)) { rbt_storePw.Active = true; } else { rbt_alwaysAsk.Active = true; } // assign event-listeners stored_pw.Changed += PasswordChanged; stored_pw2.Changed += PasswordChanged; }
/// <summary> /// Get config settings /// </summary> private bool GetConfigSettings(out string _password, out WebDAVInterface _webdav) { _password = null; _webdav = null; object ask = Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_ASKEVERYTIME); if (ask == null) { return(false); } if (((bool)ask == false)) { #if WIN32 && DPAPI object pw = DPAPIUtil.getPassword(); #else object pw = Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_PASSWORD); #endif if (pw != null) { _password = Convert.ToString(pw); // quick fix -> a num-only pw is returned as an int o.O } } if (_password == null) { // ask for password var entryWindow = new PrivateNotes.PasswordEntry(); _password = entryWindow.getPassword(); } #if USE_LOCAL_TEST _webdav = new WebDAVInterface("http://localhost", "/webdav/notes", "wampp", "xampp", false); #else Uri serverUri = new Uri(Convert.ToString(Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_SERVERPATH))); String serverHost = serverUri.GetLeftPart(UriPartial.Authority); String serverBasePath = serverUri.AbsolutePath; bool checkSslCertificates = true; object checksslobj = Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_SERVERCHECKSSLCERT); if (checksslobj != null && (checksslobj.Equals(false) || checksslobj.Equals("false"))) { checkSslCertificates = false; } string serverUser = (string)Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_SERVERUSER); string serverPass = (string)Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_SERVERPASS); Logger.Debug("will user server: " + serverHost + " path: " + serverBasePath); //Logger.Debug("creating server with user " + serverUser + " pass: " + serverPass); _webdav = new WebDAVInterface(serverHost, serverBasePath, serverUser, serverPass, checkSslCertificates); #endif if (_webdav != null && _password != null) { return(true); } return(false); }