Example #1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     AdjustAppTimer(true);
     using (FormCredential form = new FormCredential())
     {
         if (form.ShowDialog(this) == DialogResult.OK)
         {
             int NewID = dtCredentials.NewID();
             string CredentialName = form.CredentialName.EncryptTextToBase64String();
             string UserID = form.UserID.EncryptTextToBase64String();
             string Password = form.Password.EncryptTextToBase64String();
             string Link = form.Link.EncryptTextToBase64String();
             DataTable dt = Shared.GetDatabase().MergePassword(NewID, CredentialName, UserID, Password, Link);
             if (dtCredentials.Columns.Count == 0)
             {
                 dataGridView1.DataSource = null;
                 dt.Rows[0]["CredentialName"] = form.CredentialName.ToUnsecureString();
                 dtCredentials = dt;
                 dataGridView1.DataSource = dtCredentials.DefaultView;
             }
             else
             {
                 dtCredentials.Rows.Add(new object[] { NewID, form.CredentialName.ToUnsecureString(), UserID, Password, Link });
                 dtCredentials.AcceptChanges();
             }
         }
     }
     AdjustAppTimer();
 }
Example #2
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count != 1)
            {
                return;
            }

            AdjustAppTimer(true);
            if (Authenticate())
            {
                using (FormCredential form = new FormCredential())
                {
                    using (DataGridViewRow row = dataGridView1.SelectedRows[0])
                    {
                        form.CredentialID   = int.Parse(row.Cells["colID"].Value.ToString());
                        form.CredentialName = row.Cells["colName"].Value.ToString().ToSecureString();    //.DecryptBase64StringToText();
                        form.UserID         = row.Cells["colUserID"].Value.ToString().DecryptBase64StringToText();
                        form.Password       = row.Cells["colPassword"].Value.ToString().DecryptBase64StringToText();
                        if (row.Cells["colLink"].Value != null)
                        {
                            form.Link = row.Cells["colLink"].Value.ToString().DecryptBase64StringToText();
                        }

                        if (form.ShowDialog(this) == DialogResult.OK)
                        {
                            int    ID             = form.CredentialID;
                            string CredentialName = form.CredentialName.EncryptTextToBase64String();
                            string UserID         = form.UserID.EncryptTextToBase64String();
                            string Password       = form.Password.EncryptTextToBase64String();
                            string Link           = form.Link.EncryptTextToBase64String();
                            Shared.GetDatabase().MergePassword(ID, CredentialName, UserID, Password, Link);
                            DataRow dr = dtCredentials.AsEnumerable().First(r => int.Parse(r["ID"].ToString()) == ID);
                            dr["CredentialName"] = CredentialName.DecryptBase64StringToText().ToUnsecureString();
                            dr["UserID"]         = UserID;
                            dr["Password"]       = Password;
                            dr["Link"]           = Link;
                            dtCredentials.AcceptChanges();
                        }
                    }
                }
            }
            AdjustAppTimer();
        }