//Add the Credentials from the App.config to the Windows Credential Manager private void AddCredentials() { var credentialToolBox = new WindowsCredentialToolBox(); try { var credentialConfig = _provideConfiguration.GetConfiguration <CredentialConfigSection>("credentialSection"); if (credentialConfig != null && credentialConfig.Credentials.Count > 0) { foreach (CredentialConfig credential in credentialConfig.Credentials) { credentialToolBox.Add(credential.Target, credential.User, credential.Password.DecodePassword(), credential.Type, credential.Persist); } } else { Logger.Info("No Credentials available"); } } catch (Exception e) { Logger.Error("Something wrong with the credentialSection in the App.config", e); } }
public void AddCheckAndDeleteCredential() { string target = "github.com"; string user = "******"; string passWord = "******"; var addResult = _windowsCredentialToolBox.Add(target, user, passWord, WindowsCredentialTypes.CredentialType.DOMAIN_PASSWORD, WindowsCredentialTypes.CredentialPersist.LOCAL_MACHINE); addResult.Should().BeTrue(); var existResult = _windowsCredentialToolBox.Exist(target, WindowsCredentialTypes.CredentialType.DOMAIN_PASSWORD); existResult.Should().BeTrue(); var deleteResult = _windowsCredentialToolBox.Delete(target, WindowsCredentialTypes.CredentialType.DOMAIN_PASSWORD); deleteResult.Should().BeTrue(); var deleteConfirmResult = _windowsCredentialToolBox.Exist(target, WindowsCredentialTypes.CredentialType.DOMAIN_PASSWORD); deleteConfirmResult.Should().BeFalse(); }