我正在尝试为每个目标存储多个用户名和密码。问题是,每次使用相同的用户名但不同的目标和密码添加新凭据时,将删除具有相同用户名的其他凭据。
我的问题是如何在同一目标下存储多个用户名和密码?
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;
}
}
}
答案 0 :(得分:0)
您可以使用CredentialCache
来实现此目的CredentialCache cache = new CredentialCache();
cache.Add(New Uri(myProxy.Url), "NTLM", New NetworkCredential("UserName", "Password", "Domain"))