检索使用C#从Windows凭据存储凭证 [英] Retrieve Credentials from Windows Credentials Store using C#

查看:1237
本文介绍了检索使用C#从Windows凭据存储凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想查询凭证存储(或库因为它是所谓在Win8中),并获得登录数据。在MSDN是在这种情况下真的无益的,我也不想任何C ++的PInvoke方法。

I simply want to query the Credentials Store (or Vault as it is called in Win8) and get the login data. The MSDN is really unhelpful in this case and I also do not want any C++ pInvoke approaches.

我知道,类似的问题在这里已经问过几次,但是没有这些解决方案在我的情况下工作。我不使用地铁应用程序编程所以像 PasswordVault 是(因为它看起来)不可用。我只是创建一个简单的C#WPF桌面应用程序。

I know that similar questions have been asked here a few times, but none of those solutions work in my case. I do not use Metro App programming so things like PasswordVault are (as it looks) not available. I just create a simple C# WPF Desktop application.

在理想情况下,应该在几个Windows版本,但Win8的是prefered。

Ideally it should work in several Windows versions, but Win8 is prefered.

更具体地说我想从CRM插件查询存储的数据为Outlook自动有我的应用程序登录到CRM服务器,而无需用户请求他的凭据。这意味着,如果这是甚至可能...

More specifically I want to query the stored data from the CRM plugin for Outlook to automatically have my app log in to the CRM Server without having the User to ask for his Credentials. That means, if this is even possible...

那么,如何访问Windows证书商店?

So how do I access the Windows Credentials Store?

推荐答案

有就是我一直在使用所谓的CredentialManagement一个的NuGet库
<一href=\"http://nuget.org/packages/CredentialManagement/\">http://nuget.org/packages/CredentialManagement/

There is a Nuget library that I've been using called CredentialManagement http://nuget.org/packages/CredentialManagement/

用法是pretty简单。
我包了一点,但可能并不需要:

The usage is pretty simple. I wrapped it a little but probably didn't need to:

    public UserPass GetCredentials()
    {
        var cm = new Credential {Target = CredentialName};
        if (!cm.Exists())
            return null;

        cm.Load();
        var up = new UserPass(cm);
        return up;
    }

    public bool SetCredentials(UserPass up)
    {
        var cm = new Credential {Target = CredentialName, PersistanceType =  PersistanceType.Enterprise, Username = up.UserName, Password = up.Password};
        return cm.Save();
    }

    public void RemoveCredentials()
    {
        var cm = new Credential { Target = CredentialName };
        cm.Delete();

    }

如果您有兴趣自己实现它,浏览来源:
<一href=\"http://credentialmanagement.$c$cplex.com/SourceControl/latest\">http://credentialmanagement.$c$cplex.com/SourceControl/latest

If you're interested in implementing it yourself, browse the source: http://credentialmanagement.codeplex.com/SourceControl/latest

诀窍是,没有C#API到凭据管理器。
这个库很好地包装了其他的.dll文件的入口点。 : - )

The trick is that there is no C# api into the Credential Manager. This library wraps the other .dll entry points nicely. :-)

这篇关于检索使用C#从Windows凭据存储凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆