private void Save() { if (!string.IsNullOrEmpty(txtName.Text) && !string.IsNullOrEmpty(txtMail.Text) && !string.IsNullOrEmpty(txtPassword.Text)) { switch (_type) { case NewType.Modify: int i = MainForm.Accounts.FindIndex(x => x.Name() == _cryLain.Encrypt(CryLain.ToInsecureString(MainForm.Key), _name)); if (i > -1) { MainForm.Accounts.RemoveAt(i); } break; } LainAccount account = new LainAccount(_cryLain.Encrypt(CryLain.ToInsecureString(MainForm.Key), txtName.Text), _cryLain.Encrypt(CryLain.ToInsecureString(MainForm.Key), txtMail.Text), _cryLain.Encrypt(CryLain.ToInsecureString(MainForm.Key), txtPassword.Text), _cryLain.Encrypt(CryLain.ToInsecureString(MainForm.Key), txtNote.Text)); MainForm.Accounts.Add(account); txtName.Text = string.Empty; txtMail.Text = string.Empty; txtPassword.Text = string.Empty; txtNote.Text = string.Empty; account = null; this.DialogResult = DialogResult.OK; this.Close(); } }
internal NewForm(NewType type, string info = null) { InitializeComponent(); Options.ApplyTheme(this); _type = type; _name = info; switch (_type) { case NewType.Modify: btnOk.Text = "Save"; if (!string.IsNullOrEmpty(info)) { this.Text = string.Format("Edit account - {0}", info); } else { this.Text = "Add new account..."; } int i = MainForm.Accounts.FindIndex(x => x.Name() == _cryLain.Encrypt(CryLain.ToInsecureString(MainForm.Key), _name)); if (i > -1) { txtName.Text = _cryLain.Decrypt(CryLain.ToInsecureString(MainForm.Key), MainForm.Accounts[i].Name()); txtMail.Text = _cryLain.Decrypt(CryLain.ToInsecureString(MainForm.Key), MainForm.Accounts[i].Email()); txtPassword.Text = _cryLain.Decrypt(CryLain.ToInsecureString(MainForm.Key), MainForm.Accounts[i].Password()); txtNote.Text = _cryLain.Decrypt(CryLain.ToInsecureString(MainForm.Key), MainForm.Accounts[i].Note()); } break; } }
private void LoadAccounts() { AccountView.Rows.Clear(); AccountView.Refresh(); if (Options.CurrentOptions.HidePasswords) { AccountView.Columns[2].Visible = false; } else { AccountView.Columns[2].Visible = true; } foreach (LainAccount x in Accounts) { AccountView.Rows.Add(new string[] { _cryLain.Decrypt(CryLain.ToInsecureString(Key), x.Name()), _cryLain.Decrypt(CryLain.ToInsecureString(Key), x.Email()), _cryLain.Decrypt(CryLain.ToInsecureString(Key), x.Password()) }); } txtSearch.Clear(); this.Text = string.Format("Lain {0} [{1} accounts]", Program.GetCurrentVersionToString(), Accounts.Count); AccountView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); AccountView.Sort(AccountView.Columns[0], ListSortDirection.Ascending); if (AccountView.Rows.Count > 0) { AccountView.ClearSelection(); AccountView.Rows[0].Selected = true; } }
private void Remove() { var rows = AccountView.SelectedRows; if (rows.Count <= 0) { return; } string name; int i; if (Authorize(LoginType.Remove)) { foreach (DataGridViewRow row in rows) { name = row.Cells[0].Value.ToString(); i = Accounts.FindIndex(x => x.Name() == _cryLain.Encrypt(CryLain.ToInsecureString(Key), name)); if (i > -1) { Accounts.RemoveAt(i); } } LoadAccounts(); } }
private void Search() { if (string.IsNullOrEmpty(txtSearch.Text)) { clearPic.Visible = false; LoadAccounts(); } else { clearPic.Visible = true; _term = txtSearch.Text.Trim().ToLowerInvariant(); AccountView.Rows.Clear(); foreach (LainAccount la in Accounts) { _temp = _cryLain.Decrypt(CryLain.ToInsecureString(Key), la.Name()); _temp2 = _cryLain.Decrypt(CryLain.ToInsecureString(Key), la.Email()); if (_temp.ToLowerInvariant().Contains(_term) || _temp2.ToLowerInvariant().Contains(_term)) { AccountView.Rows.Add(new string[] { _cryLain.Decrypt(CryLain.ToInsecureString(Key), la.Name()), _cryLain.Decrypt(CryLain.ToInsecureString(Key), la.Email()), _cryLain.Decrypt(CryLain.ToInsecureString(Key), la.Password()) }); } } } _temp = string.Empty; _temp2 = string.Empty; }
private void Login() { if ((!string.IsNullOrEmpty(txtPassword.Text)) && (File.Exists(Required.LainSerial))) { string hashed = CryLain.HashKey(txtPassword.Text); string stored = File.ReadAllText(Required.LainSerial); if (hashed == stored) { switch (_type) { case LoginType.Login: Program.SetMainForm(new MainForm(CryLain.ToSecureString(txtPassword.Text))); this.Close(); Program.ShowMainForm(); break; case LoginType.Authorize: this.DialogResult = DialogResult.Yes; this.Close(); break; case LoginType.Remove: this.DialogResult = DialogResult.Yes; this.Close(); break; case LoginType.RemoveAll: this.DialogResult = DialogResult.Yes; this.Close(); break; } txtPassword.Text = string.Empty; hashed = string.Empty; stored = string.Empty; } else { MessageBox.Show("The password you provided is incorrect!", "ERROR: Logging in", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }