Skip to content

Instantly share code, notes, and snippets.

@grokys
Created August 25, 2017 16:20
Show Gist options
  • Select an option

  • Save grokys/fc673a863ec7dffca324d00f0c8cd278 to your computer and use it in GitHub Desktop.

Select an option

Save grokys/fc673a863ec7dffca324d00f0c8cd278 to your computer and use it in GitHub Desktop.
public Task<Tuple<string, string>> Load(HostAddress hostAddress)
{
Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));
var keyGit = GetKeyGit(hostAddress.CredentialCacheKeyHost);
var keyHost = GetKeyHost(hostAddress.CredentialCacheKeyHost);
var gitFound = false;
var hostFound = false;
Tuple<string, string> result = null;
using (var credentialGit = new Credential())
using (var credentialHost = new Credential())
{
credentialGit.Target = keyGit;
credentialGit.Type = CredentialType.Generic;
gitFound = credentialGit.Load();
credentialHost.Target = keyHost;
credentialHost.Type = CredentialType.Generic;
hostFound = credentialHost.Load();
if (gitFound && hostFound &&
credentialGit.Username == credentialHost.Username &&
credentialGit.Password == credentialHost.Password)
{
result = Tuple.Create(credentialGit.Username, credentialGit.Password);
}
else if (gitFound)
{
Save(credentialGit.Username, credentialGit.Password, hostAddress);
result = Tuple.Create(credentialGit.Username, credentialGit.Password);
}
else if (hostFound)
{
Save(credentialHost.Username, credentialHost.Password, hostAddress);
result = Tuple.Create(credentialHost.Username, credentialHost.Password);
}
}
return Task.FromResult(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment