1

The following problem is happening. Our company is changing all the passwords of the users.

They asked me to write a program so that the user can enter his or her's username and new password so this will be replaced in the windows credentials manager. (Windows Vault).

What I am trying to do is to get all the stored credentials in the credential manager with a specified username. When I find the username I will edit the password.

I do not know the Target name so I cannot find the credentials with a Target name.

I made the following script with https://www.nuget.org/packages/CredentialManagement/:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CredentialManagement;
using System.Diagnostics;
using System.Security;
using Microsoft.Win32.SafeHandles;

namespace RU_PWReplacer
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            GetCredentials();
        }

        public void GetCredentials()
        {
            List<Credential> Credentials = new List<Credential>();
            List<string> TargetPath = new List<string>();

            TargetPath.Add("test1.nl");
            TargetPath.Add("test2.nl");
            TargetPath.Add("test3.nl");

            for (int i = 0; i < TargetPath.Count; i++)
            {
                Credential Try_ToFind_Credential = new Credential { Target = TargetPath[i], Type = CredentialType.DomainPassword };
                Credentials.Add(Try_ToFind_Credential);
            }
            foreach (Credential c in Credentials)
            {
                if (!c.Exists())
                {
                    Console.Write("Not Found\n");
                }
                else
                {
                    Console.Write("Found\n");
                }
            }
        }
    }
}

The problem is that this way I am searching with a Target name and that is not a possibility, because there can be a lot of target names. So searching for a Username is more efficient.

If have found this post: How do I store and retrieve credentials from the Windows Vault credential manager?

The problem with this is that it still uses a Target name to find the credential.

I hope you guys can point me in the right direction.

With kind regards,

Dennis.

Community
  • 1
  • 1
Dennis
  • 11
  • 2
  • UPDATE: Oke I have found this : https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Credentials-d44c3cde And if I use the command: .\CredMan.ps1 -ShoCred -All I will get all the credentials. So that is good, but I this not possible in visual studio C# ? – Dennis Mar 27 '15 at 08:32

0 Answers0