Reputation: 1971
I am talking about the information visible if you open "Credential Manager" from the control panel or start menu. If you tell IE to save a password it's visible in there.
I already know about the wrapper for Advapi32.dll (http://www.nuget.org/packages/CredentialManagement/) that offers easy functionality of the functions:
CredReadW
CredWriteW
CredDeleteW
etc.
but at this point I am not even sure if those are the right functions to interact with website authentication data. I wasn't able to read existing or write new web authentication data with those functions (I don't even fully understand the credential types). Writing & reading CRED_TYPE_GENERIC credentials worked though.
How do I read and write website authentication data from C#?
I am ready to p/invoke if necessary.
Upvotes: 0
Views: 129
Reputation: 21337
As you are using Windows 8, the simplest way is to use the WinRT API. I think you are creating a desktop application (Console, WPF, WinForms), so you have to:
Add <TargetPlatformVersion>8.0</TargetPlatformVersion>
to the csproj file.
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BEA97844-0370-40C1-A435-F95DC0DC0677}</ProjectGuid>
<OutputType>Exe</OutputType>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetPlatformVersion>8.0</TargetPlatformVersion>
Add a reference to Windows
and System.Runtime
(look at the link below)
var vault = new Windows.Security.Credentials.PasswordVault();
var credentials = vault.RetrieveAll();
foreach (PasswordCredential credential in credentials)
{
Console.WriteLine("{0} {1}", credential.Resource, credential.UserName);
}
Source: http://blogs.softfluent.com/post/2014/03/27/Acceder-a-API-WinRT-depuis-une-application-Desktop.aspx (French)
To get Windows and Generic credential: Encrypting credentials in a WPF application
Upvotes: 2