6

Using the Windows.Security.Credentials.PasswordVault class, I can access the passwords stored under "Web Credentials" in the Windows Credential Manager:

using System;
using Windows.Security.Credentials;

class Program {
    static void Main(string[] args) {
        PasswordVault vault = new PasswordVault();
        foreach (var cred in vault.RetrieveAll()) {
            cred.RetrievePassword();
            Console.WriteLine("Resource: {0}", cred.Resource);
            Console.WriteLine("UserName: {0}", cred.UserName);
            Console.WriteLine("Password: {0}", cred.Password);
        }
    }
}

I would like to know if there's a way to retrieve the credentials stored under "Windows Credentials" instead.

Paolo Tedesco
  • 55,237
  • 33
  • 144
  • 193
  • To add the reference to `Windows.Security` in a desktop app, check here: http://stackoverflow.com/questions/14813370/how-to-access-the-stored-credentials-passwordvault-on-win7-and-win8 – Paolo Tedesco Mar 23 '15 at 15:41
  • Windows does not store the actual password, it is usually some type of hash of the password. The only way to get the clear text Windows password for a user is to capture it when the user types it during logon. For this you would need to write a Windows Credential provider. – Mohit A Mar 23 '15 at 15:43
  • 2
    @MohitA: I'm talking about something completely different here. I want to retrieve a password that **I stored in the Credential Manager** under Windows Credentials, I don't want to sniff some other user's password. – Paolo Tedesco Mar 23 '15 at 15:47
  • Did this solution work for you in IIS? – Chazt3n Mar 09 '16 at 16:24

1 Answers1

4

There is a Nuget library called CredentialManagement http://nuget.org/packages/CredentialManagement/ from the answer here: Retrieve Credentials from Windows Credentials Store using C#

works perfectly

        var cm = new Credential();
        cm.Target = "mycredentialname";

        if (!cm.Exists())
        {
            Console.WriteLine("cm is null");
        }
        cm.Load();
        Console.WriteLine("Password: " + cm.Password);
        Console.WriteLine("Username: " + cm.Username);
Community
  • 1
  • 1
Roenne
  • 56
  • 2