Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        public static Credentials WinCred(string url, string usernameFromUrl, SupportedCredentialTypes types)
        {
            var creds = new Credential {
                Target = url, Type = CredentialType.Generic
            };

            if (creds.Load())
            {
                return new UsernamePasswordCredentials {
                           Username = creds.Username, Password = creds.Password
                }
            }
            ;
            var uri      = new Uri(url);
            var userPart = (string.IsNullOrEmpty(usernameFromUrl) ? string.Empty : usernameFromUrl + "@");

            creds.Target = $"git:{uri.Scheme}://{userPart}{uri.Host}";

            if (!creds.Load())
            {
                creds.Target += "/";

                creds.Load();
            }

            return(new UsernamePasswordCredentials {
                Username = creds.Username, Password = creds.Password
            });
        }
Beispiel #3
0
        public bool LoadCredential(out string username, out string password)
        {
            _logger.Info("Loading credentials from store...");

            using (var credential = new CredentialManagement.Credential())
            {
                credential.Target          = RaceControlF1TV;
                credential.Type            = CredentialType.Generic;
                credential.PersistanceType = PersistanceType.LocalComputer;

                var loaded = credential.Load();

                if (loaded)
                {
                    username = credential.Username;
                    password = credential.Password;
                    _logger.Info("Credentials loaded from store.");
                }
                else
                {
                    username = null;
                    password = null;
                    _logger.Warn("Credentials not found in store.");
                }

                return(loaded);
            }
        }
Beispiel #4
0
        public bool SaveCredential(string username, string password)
        {
            _logger.Info("Saving credentials to store...");

            using (var credential = new CredentialManagement.Credential())
            {
                credential.Target          = RaceControlF1TV;
                credential.Type            = CredentialType.Generic;
                credential.PersistanceType = PersistanceType.LocalComputer;
                credential.Username        = username;
                credential.Password        = password;

                var saved = credential.Save();

                if (saved)
                {
                    _logger.Info("Credentials saved to store.");
                }
                else
                {
                    _logger.Warn("Credentials not saved to store.");
                }

                return(saved);
            }
        }
 public void Store(string username, string password)
 {
     using (var cred = new Credential(username, password, TheProduct.CredentialsTarget, CredentialType.Generic)
         {
             PersistanceType = PersistanceType.Enterprise
         })
     {
         if (cred.Save())
         {
             OnChanged();
         }
         else
         {
             throw new InvalidOperationException("Couldn't save credential to store");
         }
     }
 }
Beispiel #6
0
    public void DeleteCredential()
    {
        using var credential = new CredentialManagement.Credential
              {
                  Target          = RaceControlF1TV,
                  Type            = CredentialType.Generic,
                  PersistanceType = PersistanceType.LocalComputer
              };

        if (credential.Delete())
        {
            _logger.Info("Credentials deleted from store.");
        }
        else
        {
            _logger.Warn("Credentials not deleted from store.");
        }
    }
Beispiel #7
0
    public void SaveCredential(string username, string password)
    {
        using var credential = new CredentialManagement.Credential
              {
                  Target          = RaceControlF1TV,
                  Type            = CredentialType.Generic,
                  PersistanceType = PersistanceType.LocalComputer,
                  Username        = username,
                  Password        = password
              };

        if (credential.Save())
        {
            _logger.Info("Credentials saved to store.");
        }
        else
        {
            _logger.Warn("Credentials not saved to store.");
        }
    }
Beispiel #8
0
 private bool GetFromCredentialStore()
 {
     try
     {
         Credential credential = new Credential();
         credential.Target          = ConfigurationManager.AppSettings["CredentialStoreKey"];
         credential.Type            = CredentialType.Generic;
         credential.PersistanceType = PersistanceType.Enterprise;
         if (!credential.Load())
         {
             Utility.LogAction("Failed to load credential from credential manager ");
             return(false);
         }
         _email    = credential.Username;
         _password = credential.Password;
         return(true);
     }
     catch (Exception ex)
     {
         Utility.LogAction("Credential manager failed with exception: " + ex.Message);
         return(false);
     }
 }
        public System.Net.ICredentials GetCredentials(Uri requestUri)
        {
            var cred = new Credential
            {
                Target = serverUri.ToString(),
                PersistanceType = PersistanceType.LocalComputer,
                Type = CredentialType.Generic
            };

            if (cred.Load())
            {
                return new NetworkCredential(cred.Username, cred.Password);
            }

            cred = GetCredFromUser();

            if (cred != null)
            {
                return new NetworkCredential(cred.Username, cred.Password);
            }

            return null;
        }
Beispiel #10
0
        public bool DeleteCredential()
        {
            _logger.Info("Deleting credentials from store...");

            using (var credential = new CredentialManagement.Credential())
            {
                credential.Target          = RaceControlF1TV;
                credential.Type            = CredentialType.Generic;
                credential.PersistanceType = PersistanceType.LocalComputer;

                var deleted = credential.Delete();

                if (deleted)
                {
                    _logger.Info("Credentials deleted from store.");
                }
                else
                {
                    _logger.Warn("Credentials not deleted from store.");
                }

                return(deleted);
            }
        }
Beispiel #11
0
        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!");
                }
            }
        }
        private Credential GetCredFromUser()
        {
            var prompt = CredentialsPromptProvider.Prompt;

            if (prompt.ShowDialog() == DialogResult.OK)
            {
                var cred = new Credential
                {
                    Type = CredentialType.Generic,
                    PersistanceType = PersistanceType.LocalComputer,
                    Target = serverUri.ToString(),
                    Username = prompt.Username,
                    Password = prompt.Password
                };

                cred.Save();

                return cred;
            }
            else
            {
                return null;
            }
        }
Beispiel #13
0
 /// <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();
         }
     }
 }
Beispiel #14
0
 /// <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;
     }
 }
Beispiel #15
0
 /// <summary>
 /// Saves the provided OneDrive Refresh Token in the Windows Credential Manager
 /// </summary>
 /// <param name="databaseFilePath">Full local path to the KeePass database for which to save the OneDrive Refresh Token</param>
 /// <param name="refreshToken">The OneDrive Refresh Token to store securely in the Windows Credential Manager</param>
 public static void SaveRefreshTokenInWindowsCredentialManager(string databaseFilePath, string refreshToken)
 {
     using (var saved = new Credential(string.Empty, refreshToken, string.Concat("KoenZomers.KeePass.OneDriveSync:", databaseFilePath), CredentialType.Generic) {PersistanceType = PersistanceType.LocalComputer})
     {
         saved.Save();
     }
 }
Beispiel #16
0
        public bool Exists()
        {
            CheckNotDisposed();
            _unmanagedCodePermission.Demand();

            if (string.IsNullOrEmpty(Target))
            {
                throw new InvalidOperationException("Target must be specified to check existance of a credential.");
            }

            using (Credential existing = new Credential { Target = Target, Type = Type })
            {
                return existing.Load();
            }
        }
 private static string GetCredentialTypeAsString(Credential c)
 {
     return c.Target.Substring(c.Target.IndexOf('.') + 1, (c.Target.IndexOf(':') - c.Target.IndexOf('.') - 1));
 }
 /// <summary>
 ///     The on clear credentials.
 /// </summary>
 private void OnClearCredentials(object data)
 {
     using (var cm = new Credential { Target = "VSSonarQubeExtension", })
     {
         cm.Delete();
         this.ServerAddress = string.Empty;
         this.Password = string.Empty;
         this.UserName = string.Empty;
     }
 }
Beispiel #19
0
        private static void CredentialManagement()
        {
            //var cm = new CredentialManagement.CredentialSet();
            ////{
            ////    Target = "192.168.20.30",
            ////    //PersistanceType = PersistanceType.Enterprise,
            ////    //Username = "******",
            ////    //Password = "******",
            ////    ////Type = CredentialType.None
            ////};
            ////cm.Save();
            //cm.Load();
            //var item = cm.FirstOrDefault(cc => cc.Target == "192.168.20.30");
            //{
            //    Console.WriteLine(item.Target + "   " + item.PersistanceType + "    " + item.Type + "   " + item.Username + ":" + item.Password);
            //}

            var c = new Credential()
            {
                Target = "192.168.20.30",
                Type = CredentialType.DomainPassword,//windows 凭证 Generic 普通凭证
                PersistanceType = PersistanceType.Enterprise,//永久
                Username = "******",
                Password = "******"
            };
            c.Save();
        }
Beispiel #20
0
        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();
        }
Beispiel #21
0
        public static System.Net.NetworkCredential GetCredential(string serverip)
        {
            System.Net.NetworkCredential credentials = null;
            BaseCredentialsPrompt prompt = null;
            if (IsWinVistaOrHigher())
            {
                prompt = new VistaPrompt();
                Console.WriteLine("win7");
            }
            else
            {
                prompt = new XPPrompt() { Target = serverip };

                Console.WriteLine("xp");
            }
            prompt.SaveChecked = true;
            prompt.ShowSaveCheckBox = true;
            prompt.Title = @"指定已授权的 域(计算机)\用户";
            try
            {
                if (prompt.ShowDialog() == DialogResult.OK)
                {
                    credentials = new System.Net.NetworkCredential(prompt.Username, prompt.SecurePassword);
                    if (prompt.SaveChecked)
                    {
                        var cm = new Credential()
                        {
                            Target = serverip,
                            Type = CredentialType.DomainPassword,//windows 凭证 Generic 普通凭证
                            PersistanceType = PersistanceType.Enterprise,//永久
                            Username = prompt.Username,
                            SecurePassword = prompt.SecurePassword
                        };
                        cm.Save();
                    }
                    return credentials;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetBaseException());
            }

            return null;
        }
        /// <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>
        ///     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);
            }
        }
 /// <summary>
 /// The set credentials.
 /// </summary>
 /// <param name="userName">
 /// The user name.
 /// </param>
 /// <param name="password">
 /// The password.
 /// </param>
 private void SetCredentials(string userName, string password)
 {
     this.configurationHelper.WriteSetting(new SonarQubeProperties(Context.GlobalPropsId, OwnersId.ApplicationOwnerId, "ServerAddress", this.ServerAddress));
     using (var cm = new Credential
     {
         Target = "VSSonarQubeExtension",
         PersistanceType = PersistanceType.Enterprise,
         Username = userName,
         SecurePassword = ConnectionConfiguration.ConvertToSecureString(password)
     })
     {
         cm.Save();
     }
 }
        public bool Apply(PasswordBox password)
        {
            if (string.IsNullOrEmpty(NewUser) ||
                string.IsNullOrEmpty(NewCredential) ||
                password.SecurePassword.Length == 0) return false;

            var cred = new Credential(NewUser, ConvertToUnsecureString(password.SecurePassword), NewCredential, Type)
            {
                SecurePassword = password.SecurePassword,
                PersistanceType = PersistanceType.LocalComputer
            };

            return cred.Save();
        }