private void btn_changePassword_Click(object sender, EventArgs e) { PinForm pinForm = new PinForm(this, false); pinForm.Text = "Give current password"; if ((pinForm.ShowDialog() != DialogResult.OK) || (PIN != pinForm.maskedPIN.Text)) { MessageBox.Show("Wrong password!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } pinForm.Dispose(); pinForm = new PinForm(this, false); if (pinForm.ShowDialog() == DialogResult.OK) { PIN = pinForm.maskedPIN.Text; MessageBox.Show("Password changed succesfully"); saveToFile(); } }
public bool FirstTimeLoad(bool BReset) { if (BReset || currentDATFile.Trim() == "" || !File.Exists(currentDATFile)) { Program.baseKey.SetValue("DAT File", ""); openFileDialog1.InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath); openFileDialog1.FileName = "PKeeper.dat"; } else { openFileDialog1.InitialDirectory = Path.GetDirectoryName(CurrentDATFile); openFileDialog1.FileName = Path.GetFileName(CurrentDATFile); } if (openFileDialog1.ShowDialog() == DialogResult.OK) { if (File.Exists(openFileDialog1.FileName)) { if (MessageBox.Show("File already exists.\nDo you want to recreate the file?\nAll data will be lost!!!", "Overwrite", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes) { try { File.Delete(openFileDialog1.FileName); } catch { } Application.DoEvents(); if (File.Exists(openFileDialog1.FileName)) { MessageBox.Show("Could not overwrite file!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(FirstTimeLoad(false)); } } else { return(FirstTimeLoad(true)); } } } else { MessageBox.Show("No valid password file was chosen.\nThe program will exit!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(0); return(false); } PinForm pinForm = new PinForm(this, false); pinForm.Text = "Please enter a new password"; EnterFirstTimePIN: String tmpPIN = ""; if (pinForm.ShowDialog() == DialogResult.OK) { tmpPIN = pinForm.maskedPIN.Text; pinForm.Text = "Please verify your password"; if (pinForm.ShowDialog() == DialogResult.OK) { if (pinForm.maskedPIN.Text == tmpPIN) { PIN = tmpPIN; } else { MessageBox.Show("The passwords don't match.\nPlease retry!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); goto EnterFirstTimePIN; } currentDATFile = openFileDialog1.FileName; saveToFile(); return(true); } else { return(false); } } else { MessageBox.Show("No valid password was chosen.\nThe program will exit!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(0); return(false); } }
private bool loadFromFile(bool askForPIN = true) { String[] textLines; try { textLines = File.ReadAllLines(currentDATFile, Encoding.Default); if (textLines.Length != 0) { if (textLines[0] != "PKeeperV2") { throw new System.ArgumentException("The file \"" + currentDATFile + "\" is invalid!"); } validFile = TValidFile.validFileSelected; if (askForPIN) { PinForm pinForm = new PinForm(this, true); DialogResult dr; dr = pinForm.ShowDialog(); if (dr == DialogResult.Cancel) { MessageBox.Show("Password verification canceled by user.\nThe program will exit!", "Aborting", MessageBoxButtons.OK, MessageBoxIcon.Warning); Environment.Exit(0); } if ((dr != DialogResult.OK) || (textLines[1] != pinForm.maskedPIN.Text)) { validFile = TValidFile.validFileWrongPassword; throw new System.ArgumentException("Wrong password!"); } else { PIN = textLines[1]; } } validFile = TValidFile.validFileSelected; String[] Sections = textLines[2].Split('\a'); textLines = textLines.Skip(3).ToArray(); string[] gridData = String.Join("\n", textLines).Split('\0'); for (int x = 0; x <= listBox1.Items.Count - 1; x++) { DeleteTab(listBox1.Items[x].ToString()); } listBox1.Items.Clear(); for (int x = 0; x <= Sections.Length - 1; x++) { GridTabClass tmpGtb = AddNewTab(Sections[x]); if (x < gridData.Count()) { textToGridView(gridData[x], ref tmpGtb); } } if (listBox1.Items.Count > 0) { listBox1.SelectedIndex = 0; } DoKeys(); } else // Empty file { throw new System.ArgumentException("The passwords file is empty!"); } validFile = TValidFile.validFileSelected; btn_reloadFile.Enabled = true; return(true); } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }