//#region credential

        public static List <Credential> credentialTypes(this SecretData secretData, string credentialType)
        {
            var credentials = new List <Credential>();

            if (secretData.isNull())
            {
                return(credentials);
            }
            if (credentialType.valid().isFalse())
            {
                if (secretData.Credentials != null)
                {
                    return(secretData.Credentials);
                }
                else
                {
                    return(credentials);
                }
            }

            foreach (var credential in secretData.Credentials)
            {
                if (credential.CredentialType == credentialType)
                {
                    credentials.add(credential);
                }
            }
            return(credentials);
        }
        public static List <Credential> usernames(this SecretData secretData, string credentialType)
        {
            var usernames = from credential in secretData.credentialTypes(credentialType)
                            select credential;

            return(usernames.ToList());
        }
        public static string password(this SecretData secretData, string credentialType, int index)
        {
            var credentials = secretData.credentialTypes(credentialType);

            if (index < credentials.size())
            {
                return(credentials[index].Password);
            }
            return("");
        }
        public static string username(this SecretData secretData, string credentialType, int index)
        {
            var credentials = secretData.credentialTypes(credentialType);

            if (index < credentials.size())
            {
                return(credentials[index].UserName);
            }
            return("");
        }
 public static string password(this SecretData secretData, string credentialType, string username)
 {
     foreach (var credential in secretData.Credentials)
     {
         if (credential.UserName == username && credential.CredentialType == credentialType)
         {
             return(credential.Password);
         }
     }
     return("");
 }
Exemplo n.º 6
0
 public void createNewSecretsFile()
 {
     var secretData = new SecretData();
     var fileName = "What is the new file name".askUser();
     if (fileName.valid())
     {
         if (fileName.extension(".xml").isFalse())
             fileName+=".xml";
         selectedFile = directory.getCurrentDirectory().pathCombine(fileName);
         secretData.serialize(selectedFile);
         statusMessage("Created new File: {0}".format(selectedFile));
     }
 }
 public static Credential get_User(this SecretData secretData, string credentialType, string userName)
 {
     if (secretData != null && secretData.Credentials != null)
     {
         foreach (var credential in secretData.Credentials)
         {
             if (credential.UserName == userName)
             {
                 if (credentialType.valid().isFalse() || credentialType == credential.CredentialType)
                 {
                     return(credential);
                 }
             }
         }
     }
     return(null);
 }
Exemplo n.º 8
0
 public void saveLoadedSecretsFile()
 {
     if (selectedFile.valid().isFalse())
     {
         statusMessage("Error: no file loaded");
         return;
     }
     dataGridView.enabled(false);
     var secretData = new SecretData();
     foreach (var row in dataGridView.rows())
         if ((row[0] as string).valid())
             secretData.Credentials.createTypeAndAddToList(
             row[0],
             row[1],
             row[2],
             row[3],
             row[4]);
     secretData.serialize(selectedFile);
     dataGridView.enabled(true);
     statusMessage("Saved to file: {0}".format(selectedFile));
 }
 public static Credential credential(this SecretData secretData, string credentialTypeOrName)
 {
     if (secretData != null)
     {
         var credentials = secretData.credentialTypes(credentialTypeOrName);
         if (credentials != null && credentials.size() > 0)
         {
             return(credentials[0]);
         }
         "Finding by Username".debug();
         foreach (var credential in secretData.Credentials)
         {
             if (credential.CredentialType == credentialTypeOrName || credential.UserName == credentialTypeOrName)
             {
                 "found credential.UserName: {0} with type: {1}".info(credential.UserName, credential.CredentialType);
                 return(credential);
             }
         }
     }
     return(null);
 }
        //#endregion

        // #region username

        public static string username(this SecretData secretData)
        {
            return(secretData.username("", 0));
        }
 public static string username(this SecretData secretData, string credentialType)
 {
     return(secretData.username(credentialType, 0));
 }
 public static string username(this SecretData secretData, int index)
 {
     return(secretData.username("", index));
 }
 public static List <Credential> usernames(this SecretData secretData)
 {
     return(secretData.usernames(""));
 }
 public static string password(this SecretData secretData, int index)
 {
     return(secretData.password("", index));
 }
 public static string password(this SecretData secretData, string credentialType)
 {
     return(secretData.password(credentialType, 0));
 }
        //#region password

        public static string password(this SecretData secretData)
        {
            return(secretData.password("", 0));
        }
        //#region get_User

        public static Credential get_User(this SecretData secretData, string userName)
        {
            return(secretData.get_User("", userName));
        }