Пример #1
0
 private void cmdAddUserNameToCache_Click(object sender, EventArgs e)
 {
     try
     {
         QuickMon.Security.CredentialManager credMan = new Security.CredentialManager();
         if (txtMasterKeyFilePath.Text.Length > 0 && System.IO.File.Exists(txtMasterKeyFilePath.Text))
         {
             credMan.OpenCache(txtMasterKeyFilePath.Text);
         }
         credMan.MasterKey = txtMasterKey.Text;
         QuickMon.Security.LogonDialog ld = new QuickMon.Security.LogonDialog();
         if (lvwUserNameCache.SelectedItems.Count == 1)
         {
             ld.UserName = lvwUserNameCache.SelectedItems[0].Text;
         }
         if (ld.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             credMan.SetAccount(ld.UserName, ld.Password);
             credMan.SaveCache(txtMasterKeyFilePath.Text);
             if (lvwUserNameCache.SelectedItems.Count == 1)
             {
                 lvwUserNameCache.SelectedItems[0].SubItems[1].Text = "Yes";
                 lvwUserNameCache.SelectedItems[0].SubItems[2].Text = "Yes";
             }
             RefreshUserNameList();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #2
0
 private void cmdRemoveUserNameFromCache_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to delete the selected entry(s)?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
     {
         QuickMon.Security.CredentialManager credMan = new Security.CredentialManager();
         credMan.MasterKey = txtMasterKey.Text;
         try
         {
             credMan.OpenCache(txtMasterKeyFilePath.Text);
             foreach (int index in (from int i in lvwUserNameCache.SelectedIndices
                                    orderby i descending
                                    select i))
             {
                 try
                 {
                     credMan.RemoveAccount(lvwUserNameCache.Items[index].Text);
                 }
                 catch { }
             }
             credMan.SaveCache(txtMasterKeyFilePath.Text);
             RefreshUserNameList();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Пример #3
0
 private void inCacheToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (lvwUserNameCache.SelectedItems.Count == 1)
     {
         QuickMon.Security.CredentialManager credMan = new Security.CredentialManager();
         try
         {
             credMan.MasterKey = txtApplicationMasterKey.Text;
             if (txtApplicationMasterKeyFilePath.Text.Length > 0 && System.IO.File.Exists(txtApplicationMasterKeyFilePath.Text))
             {
                 credMan.OpenCache(txtApplicationMasterKeyFilePath.Text);
                 if (credMan.IsAccountPersisted(lvwUserNameCache.SelectedItems[0].Text))
                 {
                     if (credMan.IsAccountDecryptable(lvwUserNameCache.SelectedItems[0].Text))
                     {
                         MessageBox.Show("Selected user account is in the cache and can be decrypted with specified master key.", "Cache", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     }
                     else
                     {
                         MessageBox.Show("Selected user account is in the cache but it cannot be decrypted with specified master key!", "Cache", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     }
                 }
                 else
                 {
                     MessageBox.Show("Selected user account is not in the cache", "Cache", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Пример #4
0
        public static string GetAccountPassword(string persistedStorageLocation, string masterKey, string username)
        {
            string password = "";

            try
            {
                CredentialManager credMan = new CredentialManager();
                credMan.MasterKey = masterKey;
                credMan.OpenCache(persistedStorageLocation);
                password = credMan.GetAccountPassword(username);
            }
            catch { }
            return(password);
        }
Пример #5
0
        public static bool IsAccountDecryptable(string persistedStorageLocation, string masterKey, string username)
        {
            bool found = false;

            try
            {
                CredentialManager credMan = new CredentialManager();
                credMan.MasterKey = masterKey;
                credMan.OpenCache(persistedStorageLocation);
                found = credMan.IsAccountDecryptable(username);
            }
            catch { }
            return(found);
        }
Пример #6
0
        private void cmdRemoveUserNameFromCache_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete the selected entry(s)?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                QuickMon.Security.CredentialManager credMan = new Security.CredentialManager();
                credMan.MasterKey = txtMasterKey.Text;
                try
                {
                    credMan.OpenCache(txtMasterKeyFilePath.Text);
                    foreach (int index in (from int i in lvwUserNameCache.SelectedIndices
                                           orderby i descending
                                           select i))
                    {
                        //if (SelectedMonitorPack.CollectorHosts != null && SelectedMonitorPack.CollectorHosts.Count > 0)
                        //{
                        //    foreach (CollectorHost host in (from ch in SelectedMonitorPack.CollectorHosts
                        //                                    where ch.RunAs == lvwUserNameCache.Items[index].Text
                        //                                 select ch))
                        //    {
                        //        host.RunAs = "";
                        //    }
                        //}

                        try
                        {
                            credMan.RemoveAccount(lvwUserNameCache.Items[index].Text);
                        }
                        catch { }
                        //lvwUserNameCache.Items.RemoveAt(index);
                    }
                    credMan.SaveCache(txtMasterKeyFilePath.Text);
                    RefreshUserNameList();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #7
0
        private void cmdAddUserNameToCache_Click(object sender, EventArgs e)
        {
            QuickMon.Security.CredentialManager credMan = new Security.CredentialManager();
            try
            {
                credMan.MasterKey = txtApplicationMasterKey.Text;
                if (txtApplicationMasterKeyFilePath.Text.Length > 0 && System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtApplicationMasterKeyFilePath.Text)))
                {
                    if (System.IO.File.Exists(txtApplicationMasterKeyFilePath.Text))
                    {
                        credMan.OpenCache(txtApplicationMasterKeyFilePath.Text);
                    }

                    QuickMon.Security.LogonDialog ld = new QuickMon.Security.LogonDialog();
                    if (lvwUserNameCache.SelectedItems.Count == 1)
                    {
                        ld.UserName = lvwUserNameCache.SelectedItems[0].Text;
                    }
                    if (ld.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        credMan.SetAccount(ld.UserName, ld.Password);
                        credMan.SaveCache(txtApplicationMasterKeyFilePath.Text);
                    }
                    if ((from ListViewItem l in lvwUserNameCache.Items
                         where l.Text == ld.UserName
                         select l).Count() == 0)
                    {
                        ListViewItem lvi = lvwUserNameCache.Items.Add(ld.UserName);
                        lvi.ImageIndex = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }