45

Credentials Store (または Windows 8 ではVaultと呼ばれる)にクエリを実行し、ログイン データを取得したいだけです。この場合、MSDN はまったく役に立ちません。また、C++ P/Invokeアプローチも必要ありません。

ここで同様の質問が数回行われたことは知っていますが、私の場合、これらの解決策はどれも機能しません。私は Metro アプリ プログラミングを使用していないため、PasswordVault(見た目のように) 利用できないものがあります。簡単な C# WPF デスクトップ アプリケーションを作成するだけです。

理想的には、複数の Windows バージョンで動作するはずですが、Windows 8 が推奨されます。

より具体的には、Outlook の CRM プラグインから保存されたデータをクエリして、ユーザーが資格情報を要求することなく、アプリケーションが自動的に CRM サーバーにログインするようにしたいと考えています。つまり、これが可能であれば...

では、Windows Credentials Store にアクセスするにはどうすればよいでしょうか?

4

4 に答える 4

4

これはWindows Server 2012から機能します。テストする Windows 8 ボックスがありません。

.NET デスクトップ アプリケーションでの Windows 8 WinRT API の使用

要するに

  1. プロジェクトファイルをアンロード
  2. 編集する
  3. <TargetPlatformVersion>8.0</TargetPlatformVersion> をPropertyGroupパーツに追加します
  4. Windows.Security への参照を追加します (Windows ライブラリのリストが表示されます)。
  5. System.Runtime.WindowsRuntime.dll場所を追加C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5

次に、これを使用できます(ここから):

private string resourceName = "My App";
private string defaultUserName;

private void Login()
{
    var loginCredential = GetCredentialFromLocker();

    if (loginCredential != null)
    {
        // There is a credential stored in the locker.
        // Populate the Password property of the credential
        // for automatic login.
        loginCredential.RetrievePassword();
    }
    else
    {
        // There is no credential stored in the locker.
        // Display UI to get user credentials.
        loginCredential = GetLoginCredentialUI();
    }

    // Log the user in.
    ServerLogin(loginCredential.UserName, loginCredential.Password);
}


private Windows.Security.Credentials.PasswordCredential GetCredentialFromLocker()
{
    Windows.Security.Credentials.PasswordCredential credential = null;

    var vault = new Windows.Security.Credentials.PasswordVault();
    var credentialList = vault.FindAllByResource(resourceName);
    if (credentialList.Count > 0)
    {
        if (credentialList.Count == 1)
        {
            credential = credentialList[0];
        }
        else
        {
            // When there are multiple usernames,
            // retrieve the default username. If one doesn’t
            // exist, then display UI to have the user select
            // a default username.

            defaultUserName = GetDefaultUserNameUI();

            credential = vault.Retrieve(resourceName, defaultUserName);
        }
    }
    return credential;
}
于 2014-06-09T08:26:59.083 に答える
3

Randy からの回答System.Stringはパスワードの保存に使用されますが、これは安全ではありません。System.Security.SecureStringその目的のために使用したいと思うでしょう。

Credential Management with the .NET Framework 2.0 を読んだ方がよいでしょう。

于 2014-05-08T15:19:42.603 に答える