pGina.Configuration.CredProv.FromRegString C# (CSharp) Method

FromRegString() public static method

public static FromRegString ( string str ) : CredProv
str string
return CredProv
        public static CredProv FromRegString(string str)
        {
            string[] parts = str.Split(new string[] { "\t" }, StringSplitOptions.RemoveEmptyEntries);
            CredProv result = new CredProv
            {
                Uuid = new Guid(parts[0])
            };
            int filter = Convert.ToInt32(parts[1]);
            if ((filter & 0x1) != 0) result.FilterLogon = true;
            if ((filter & 0x2) != 0) result.FilterUnlock = true;
            if ((filter & 0x4) != 0) result.FilterChangePass = true;
            if ((filter & 0x8) != 0) result.FilterCredUI = true;
            return result;
        }

Usage Example

Beispiel #1
0
        public static List <CredProv> LoadCredProvsAndFilterSettings()
        {
            Dictionary <Guid, CredProv> result = new Dictionary <Guid, CredProv>();

            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(CRED_PROV_KEY))
            {
                if (key != null)
                {
                    string[] subKeys = key.GetSubKeyNames();
                    foreach (string sub in subKeys)
                    {
                        using (RegistryKey cpKey = key.OpenSubKey(sub))
                        {
                            if (cpKey != null)
                            {
                                CredProv credProv = new CredProv
                                {
                                    Uuid = new Guid(sub)
                                };

                                object name = cpKey.GetValue("");

                                if (name != null)
                                {
                                    credProv.Name = name.ToString();
                                }
                                else
                                {
                                    credProv.Name = credProv.Uuid.ToString();
                                }

                                if (!result.ContainsKey(credProv.Uuid))
                                {
                                    result.Add(credProv.Uuid, credProv);
                                }
                            }
                        }
                    }
                }
            }

            // Load filter settings from registry
            string[]        filterSettings     = pGina.Core.Settings.Get.CredentialProviderFilters;
            List <CredProv> filterSettingsList = new List <CredProv>();

            foreach (string s in filterSettings)
            {
                filterSettingsList.Add(CredProv.FromRegString(s));
            }

            // Merge registry settings into the dictionary
            foreach (CredProv cp in filterSettingsList)
            {
                if (result.ContainsKey(cp.Uuid))
                {
                    cp.Name         = result[cp.Uuid].Name;
                    result[cp.Uuid] = cp;
                }
            }

            return(result.Values.ToList());
        }