private void btnSave_Click(object sender, EventArgs e) { objCre = new Credential(); objCre.Username = txtUserName.Text.Trim(); objCre.Password = txtPassword.Text.Trim(); objCre.Target = txtDomainKey.Text.Trim(); if (!ControlsValidate()) { MessageBox.Show("Enter all fields"); } else { if (objCre.Exists()) { MessageBox.Show("Sorry, Already Exists!"); } else { objCre.Save(); MessageBox.Show("Saved!"); ClearFields(); LoadCredential(false); } } }
private void btnExistCheck_Click(object sender, EventArgs e) { objCre = new Credential(); objCre.Username = txtUserName.Text.Trim(); objCre.Password = txtPassword.Text.Trim(); objCre.Target = txtDomainKey.Text.Trim(); if (!ControlsValidate()) { MessageBox.Show("Enter all fields"); } else { if (objCre.Exists()) { MessageBox.Show("Already Exists!"); } else { MessageBox.Show("Congrats, Available!"); } } }
/// <summary> /// The get credentials. /// </summary> private void GetCredentials() { using (var cm = new Credential { Target = "VSSonarQubeExtension" }) { if (!cm.Exists()) { return; } cm.Load(); string address = "http://localhost:9000"; try { address = this.configurationHelper.ReadSetting(Context.GlobalPropsId, OwnersId.ApplicationOwnerId, "ServerAddress").Value; } catch (Exception ex) { this.notificationManager.ReportMessage(new Message { Id = "GeneralConfigurationViewModel", Data = "Failed To Connect To Server: " + ex.Message }); this.notificationManager.ReportException(ex); } string bootatstart = "false"; try { bootatstart = this.configurationHelper.ReadSetting(Context.GlobalPropsId, OwnersId.ApplicationOwnerId, GlobalIds.IsConnectAtStartOn).Value; } catch (Exception ex) { this.notificationManager.ReportMessage(new Message { Id = "GeneralConfigurationViewModel", Data = "Failed To Get Connect at Start: " + ex.Message }); } this.UserName = cm.Username; this.Password = ConnectionConfiguration.ConvertToUnsecureString(cm.SecurePassword); this.ServerAddress = address; if (address != null) { AuthtenticationHelper.EstablishAConnection(this.restService, address, cm.Username, ConnectionConfiguration.ConvertToUnsecureString(cm.SecurePassword)); } } }
/// <summary> /// Deletes a OneDrive Refresh Token from the Windows Credential Manager /// </summary> /// <param name="databaseFilePath">Full local path to the KeePass database for which to delete the OneDrive Refresh Token</param> public static void DeleteRefreshTokenFromWindowsCredentialManager(string databaseFilePath) { using (var credential = new Credential {Target = string.Concat("KoenZomers.KeePass.OneDriveSync:", databaseFilePath), Type = CredentialType.Generic}) { // Verify if we have stored a token for this database if (credential.Exists()) { // Delete the Windows Credential Manager entry credential.Delete(); } } }
/// <summary> /// Retrieves a OneDrive Refresh Token from the Windows Credential Manager /// </summary> /// <param name="databaseFilePath">Full local path to the KeePass database for which to retrieve the OneDrive Refresh Token</param> /// <returns>OneDrive Refresh Token if available or NULL if no Refresh Token found for the provided database</returns> public static string GetRefreshTokenFromWindowsCredentialManager(string databaseFilePath) { using (var credential = new Credential {Target = string.Concat("KoenZomers.KeePass.OneDriveSync:", databaseFilePath), Type = CredentialType.Generic}) { credential.Load(); return credential.Exists() ? credential.Password : null; } }
/// <summary> /// The get credentials. /// </summary> private void GetCredentials() { var cm = new Credential { Target = "VSSonarQubeExtension", }; if (!cm.Exists()) { return; } cm.Load(); try { string address = this.configurationHelper.ReadSetting(Context.GlobalPropsId, OwnersId.ApplicationOwnerId, "ServerAddress").Value; string bootatstart = this.configurationHelper.ReadSetting(Context.GlobalPropsId, OwnersId.ApplicationOwnerId, GlobalIds.IsConnectAtStartOn).Value; if (address != null && bootatstart.Equals("true")) { if (AuthtenticationHelper.EstablishAConnection(this.restService, address, cm.Username, ConnectionConfiguration.ConvertToUnsecureString(cm.SecurePassword))) { this.UserName = cm.Username; this.ServerAddress = address; this.Password = ConnectionConfiguration.ConvertToUnsecureString(cm.SecurePassword); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
static void Main(string[] args) { var c = new Credential() { Target = "192.168.20.195", Type = CredentialType.DomainPassword,//windows 凭证 Generic 普通凭证 PersistanceType = PersistanceType.Enterprise,//永久 }; if (c.Exists()) { c.Load(); Console.WriteLine(c.Username); } //GetCredential("192.168.20.30"); //using (PrincipalContext context = new PrincipalContext(ContextType.Machine, "192.168.20.30",null,ContextOptions.Negotiate)) //{ // //if (!currentUser.ToLower().StartsWith("lanxum\\")) // //{ // // Validate(domain, context, new Exception("当前用户未登录域")); // //} // //else // { // try // { // var upUser = GroupPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "wcl"); // } // catch (Exception ex) // { // //Validate(domain, context, ex); // } // } //} //var cm = new VistaPrompt(); ////cm.Domain = "lanxum"; //cm.SaveChecked = true; //cm.ShowSaveCheckBox = true; //cm.Title = @"指定已授权的 域(计算机)\用户"; //cm.Message = "123213"; //DialogResult rs = cm.ShowDialog(); ////CredentialManagement(); var us = c.Username.Split('\\'); var httpClient = new HttpClient(new HttpClientHandler() { //UseDefaultCredentials = true Credentials = new System.Net.NetworkCredential(@"transfer218", "Lanxum1234", "WIN-6U432IIN") }); httpClient.GetStringAsync("http://192.168.20.195:8090").ContinueWith(t => { if (t.IsFaulted) { Console.WriteLine(t.Exception.GetBaseException()); } else { Console.WriteLine(t.Result); } }); //var c = new Credential() //{ // Target = "192.168.20.30", // Type = CredentialType.DomainPassword,//windows 凭证 Generic 普通凭证 // PersistanceType = PersistanceType.Enterprise,//永久 // Username = "******", // SecurePassword = cm.SecurePassword, //}; //c.Save(); Console.ReadKey(); }