/// <summary> /// Prompts for the password to use to decrypt the server list. /// Returns the secure hash of the password entered. /// </summary> /// <param name="isRetry"></param> /// <returns></returns> private static byte[] PromptForMasterPassword(bool isRetry) { // close the splash screen before opening the password dialog (the dialog comes up behind the splash screen) Program.CloseSplash(); using (var dialog = new LoadSessionDialog(isRetry)) if (dialog.ShowDialog(Program.MainWindow) == DialogResult.OK) { return(dialog.PasswordHash); } return(null); }
public static void RestoreSession() { if (Program.RunInAutomatedTestMode) { Program.SkipSessionSave = true; Properties.Settings.Default.SaveSession = false; return; } if (!Registry.AllowCredentialSave) { Program.SkipSessionSave = true; Properties.Settings.Default.SaveSession = false; Properties.Settings.Default.RequirePass = false; RestoreSessionWithPassword(null, false); return; } Program.MasterPassword = null; if (Properties.Settings.Default.SaveSession || Properties.Settings.Default.RequirePass) { if (Properties.Settings.Default.ServerList != null && Properties.Settings.Default.ServerList.Length > 0 || Properties.Settings.Default.ServerAddressList != null && Properties.Settings.Default.ServerAddressList.Length > 0) { if (!Properties.Settings.Default.RequirePass) { Program.SkipSessionSave = true; RestoreSessionWithPassword(null, true); return; } // close the splash screen before opening the password dialog (the main window closes the // splash screen after this method is called, however, this cannot happen because the dialog // is launched modally blocking the UI thread and is additionally behind the splash screen) Program.CloseSplash(); string password = null; do { using (var dialog = new LoadSessionDialog(password != null)) password = dialog.ShowDialog(Program.MainWindow) == DialogResult.OK ? dialog.Password : null; } while (password != null && !RestoreSessionWithPassword(password, true)); Properties.Settings.Default.SaveSession = password != null; Properties.Settings.Default.RequirePass = true; Program.SkipSessionSave = true; if (password == null) { RestoreSessionWithPassword(null, false); //if the user has cancelled start a new session } else { Program.MasterPassword = EncryptionUtils.ComputeHash(password); } } else { Properties.Settings.Default.RequirePass = false; Properties.Settings.Default.SaveSession = false; } } else { Program.SkipSessionSave = true; RestoreSessionWithPassword(null, false); } }