1

我试图为每个目标存储超过 1 个用户名和密码。问题是每次添加具有相同用户名但目标和密码不同的新凭据时,具有相同用户名的其他凭据都会被删除。

我的问题是如何在同一个目标下存储多个用户名和密码?

public class PasswordRepository
{
    public string username;
    public string temp;
    LoggedIn li = new LoggedIn();
    public void SavePassword(string password, string PasswordName)
    {
        using (var cred = new Credential())
        {
            cred.Password = password;
            cred.Target = username;
            cred.Username = PasswordName;
            cred.Type = CredentialType.Generic;
            cred.PersistanceType = PersistanceType.LocalComputer;
            cred.Save();
        }
        temp = "";
    }

    public string GetPassword()
    {
        using (var cred = new Credential())
        {
            cred.Target = username;
            cred.Load();
            Debug.WriteLine(cred.Password +"    "+cred.Username);
            temp = cred.Password;
            return cred.Password;
        }
    }
}

https://www.nuget.org/packages/CredentialManagement/

4

1 回答 1

0

您可以通过使用 CredentialCache 来实现这一点

CredentialCache cache = new CredentialCache();
cache.Add(New Uri(myProxy.Url), "NTLM", New NetworkCredential("UserName", "Password", "Domain"))

MSDN

于 2017-03-20T15:30:57.223 回答