Ejemplo n.º 1
0
        internal static void SetNewPassword(string url, string user, string password)
        {
            var entry = GitManager.GitCredentials.GetEntry(url);

            if (SeletedAdapter != null)
            {
                try
                {
                    if (!SeletedAdapter.SavePassword(SeletedAdapter.FormatUrl(url), user, password, true))
                    {
                        Debug.LogErrorFormat("Could not save new Password to {0} with URL: {1}", GetAdapterName(SeletedAdapter), SeletedAdapter.FormatUrl(url));
                        return;
                    }

                    if (entry != null)
                    {
                        entry.SetHasPassword(true);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("There was a problem while trying to save credentials to " + GetAdapterName(SeletedAdapter));
                    Debug.LogException(e);
                }
                return;
            }


            if (entry != null)
            {
                entry.EncryptPassword(password);
                EditorUtility.SetDirty(GitManager.GitCredentials);
                AssetDatabase.SaveAssets();
            }
        }
Ejemplo n.º 2
0
        internal void SetNewPassword(GitCredential entry, SecureString password)
        {
            if (SeletedAdapter != null)
            {
                try
                {
                    if (!SeletedAdapter.SavePassword(entry.ManagerUrl, null, password, false))
                    {
                        logger.LogFormat(LogType.Error, "Could not save new Password to {0} with URL: {1}", GetAdapterName(SeletedAdapter), entry.ManagerUrl);
                        return;
                    }
                }
                catch (Exception e)
                {
                    logger.LogFormat(LogType.Error, "There was a problem while trying to save credentials to {0}", GetAdapterName(SeletedAdapter));
                    logger.LogException(e);
                }
                return;
            }

            if (entry != null)
            {
                entry.EncryptPassword(password);
                gitCredentials.MarkDirty();
            }
        }
Ejemplo n.º 3
0
        internal void SetNewUsername(GitCredential entry, string username)
        {
            if (SeletedAdapter != null)
            {
                try
                {
                    if (!SeletedAdapter.SaveUsername(entry.ManagerUrl, username))
                    {
                        logger.LogFormat(LogType.Error, "Could not set new Username to {0} with URL: {1}", GetAdapterName(SeletedAdapter), entry.ManagerUrl);
                        return;
                    }
                }
                catch (Exception e)
                {
                    logger.LogFormat(LogType.Error, "There was a problem while trying to set username to {0}", GetAdapterName(SeletedAdapter));
                    logger.LogException(e);
                }
                return;
            }

            if (entry != null)
            {
                entry.SetUsername(username);
                gitCredentials.MarkDirty();
            }
        }
Ejemplo n.º 4
0
        internal static void SetNewUsername(string url, string user)
        {
            if (SeletedAdapter != null)
            {
                try
                {
                    if (!SeletedAdapter.SaveUsername(SeletedAdapter.FormatUrl(url), user))
                    {
                        Debug.LogErrorFormat("Could not save new Username to {0} with URL: {1}", GetAdapterName(SeletedAdapter), SeletedAdapter.FormatUrl(url));
                        return;
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("There was a problem while trying to save credentials to " + GetAdapterName(SeletedAdapter));
                    Debug.LogException(e);
                }
            }

            var entry = gitCredentials.GetEntry(url);

            if (entry != null)
            {
                entry.SetUsername(user);
                gitCredentials.MarkDirty();
            }
        }
Ejemplo n.º 5
0
 internal string GetFormatedUrl(string url)
 {
     if (SeletedAdapter != null)
     {
         return(SeletedAdapter.FormatUrl(url));
     }
     return(url);
 }
Ejemplo n.º 6
0
        internal bool HasPassword(GitCredential entry)
        {
            if (SeletedAdapter != null)
            {
                if (string.IsNullOrEmpty(entry.Username))
                {
                    return(SeletedAdapter.Exists(entry.ManagerUrl));
                }
                return(SeletedAdapter.Exists(entry.ManagerUrl, entry.Username));
            }

            return(entry != null && entry.HasStoredPassword);
        }
Ejemplo n.º 7
0
 internal void CreateNewExternal(string url, string username, SecureString password)
 {
     try
     {
         if (!SeletedAdapter.SavePassword(url, username, password, true))
         {
             logger.LogFormat(LogType.Error, "Could not create new Entry to with URL: {0} and Username: {1} in {2}", url, username, GetAdapterName(SeletedAdapter));
             return;
         }
     }
     catch (Exception e)
     {
         logger.LogFormat(LogType.Error, "There was a problem while trying to save credentials to {0}", GetAdapterName(SeletedAdapter));
         logger.LogException(e);
     }
     return;
 }
Ejemplo n.º 8
0
        internal static string LoadPassword(GitCredentials.Entry entry)
        {
            string pass = null;

            if (SeletedAdapter != null)
            {
                try
                {
                    if (!SeletedAdapter.LoadPassword(SeletedAdapter.FormatUrl(entry.URL), ref pass))
                    {
                        Debug.LogFormat("Could not load password with URL: {0} from {1}", entry.URL, GetAdapterName(SeletedAdapter));
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("There was an error while trying to load credentials from Windows Credentials Manager");
                    Debug.LogException(e);
                }
            }

            return(pass ?? entry.DecryptPassword());
        }
Ejemplo n.º 9
0
        internal static void DeleteCredentials(string url)
        {
            var entry = GitManager.GitCredentials.GetEntry(url);

            if (SeletedAdapter != null)
            {
                try
                {
                    SeletedAdapter.DeleteCredentials(SeletedAdapter.FormatUrl(url));
                }
                catch (Exception e)
                {
                    Debug.LogError("There was an error while trying to remove credentials form " + GetAdapterName(SeletedAdapter));
                    Debug.LogException(e);
                }
            }

            if (entry != null)
            {
                GitManager.GitCredentials.RemoveEntry(entry);
            }
        }
Ejemplo n.º 10
0
        internal static void ClearCredentialPassword(string url)
        {
            var entry = GitManager.GitCredentials.GetEntry(url);

            if (SeletedAdapter != null)
            {
                try
                {
                    SeletedAdapter.DeleteCredentials(SeletedAdapter.FormatUrl(url));
                }
                catch (Exception e)
                {
                    Debug.LogError("There was an error while trying to remove credentials form " + GetAdapterName(SeletedAdapter));
                    Debug.LogException(e);
                }
            }

            if (entry != null)
            {
                entry.ClearPassword();
                entry.SetHasPassword(false);
            }
        }
Ejemplo n.º 11
0
        internal SecureString LoadPassword(GitCredential entry)
        {
            if (SeletedAdapter != null)
            {
                try
                {
                    SecureString pass;
                    if (SeletedAdapter.LoadPassword(entry.ManagerUrl, out pass))
                    {
                        return(pass);
                    }
                }
                catch (Exception e)
                {
                    logger.Log(LogType.Error, "There was an error while trying to load credentials from Windows Credentials Manager");
                    logger.LogException(e);
                }

                return(new SecureString());
            }

            return(entry.DecryptPassword());
        }
Ejemplo n.º 12
0
        internal string LoadUsername(GitCredential entry)
        {
            if (SeletedAdapter != null)
            {
                try
                {
                    string username;
                    if (SeletedAdapter.LoadUsername(entry.ManagerUrl, out username))
                    {
                        return(username);
                    }
                }
                catch (Exception e)
                {
                    logger.Log(LogType.Error, "There was an error while trying to load credentials from Windows Credentials Manager");
                    logger.LogException(e);
                }

                return("");
            }

            return(entry.Username);
        }