/// <summary> /// Saves teh given Network Credential into Windows Credential store /// </summary> /// <param name="Target">Name of the application/Url where the credential is used for</param> /// <param name="credential">Credential to store</param> /// <returns>True:Success, False:Failure</returns> public static bool SaveCredentials(string Target, NetworkCredential credential) { // Go ahead with what we have are stuff it into the CredMan structures. Credential cred = new Credential(credential); cred.TargetName = Target; cred.Persist = NativeCode.Persistance.Entrprise; NativeCode.NativeCredential ncred = cred.GetNativeCredential(); // Write the info into the CredMan storage. return(NativeCode.CredWrite(ref ncred, 0)); }
/// <summary> /// Saves teh given Network Credential into Windows Credential store /// </summary> /// <param name="Target">Name of the application/Url where the credential is used for</param> /// <param name="credential">Credential to store</param> /// <returns>True:Success, False:Failure</returns> public static bool SaveCredentials(string Target, NetworkCredential credential) { // Go ahead with what we have are stuff it into the CredMan structures. Credential cred = new Credential(credential); cred.TargetName = Target; cred.Persist = NativeCode.Persistance.Entrprise; NativeCode.NativeCredential ncred = cred.GetNativeCredential(); // Write the info into the CredMan storage. try { return NativeCode.CredWrite(ref ncred, 0); } catch (Exception e) { log.error($"Failed saving credentials for {Target}", e); return false; } }