public bool Exists()
{
CheckNotDisposed();
UnmanagedCodePermission.Demand();
if (string.IsNullOrEmpty(Target))
throw new InvalidOperationException("Target must be specified to check existance of a credential.");
using (var existing = new Credential {Target = Target, Type = Type})
{
return existing.Load();
}
}
public static string GetPassword(Uri targetUri, string username) { using (Credential creds = new Credential()) { creds.Target = GetTargetString(targetUri, username); creds.PersistenceType = PersistenceType.LocalComputer; if (creds.Exists()) { creds.Load(); return creds.Password; } else { return null; } } }