Access Windows Credentials in Credential Manager
Asked Answered
A

1

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.

Ajani answered 23/3, 2015 at 15:36 Comment(4)
To add the reference to Windows.Security in a desktop app, check here: #14813870Ajani
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.Omphalos
@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.Ajani
Did this solution work for you in IIS?Sellars
D
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);
Drescher answered 19/1, 2016 at 11:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.