Exemplo n.º 1
0
        private ResponseData FindCredentials(string url)
        {
            var notFound = new ResponseData
            {
                Entries = new ResponseEntry[0]
            };

            if (_pHost == null)
            {
                return(notFound);
            }

            if (_plugin.CryptoKey == null)
            {
                return(notFound);
            }

            if (!_pHost.Database.IsOpen)
            {
                return(notFound);
            }

            var cleanedSite = new UrlStripper(url);


            var sp = SearchParameters.None;

            sp.SearchString   = url;
            sp.SearchInUrls   = true;
            sp.SearchInTitles = true;
            sp.ExcludeExpired = true;

            var tmpResults = new PwObjectList <PwEntry>();

            _pHost.Database.RootGroup.SearchEntries(sp, tmpResults);

            while (cleanedSite.CanStrip)
            {
                var tmpRes = new PwObjectList <PwEntry>();
                sp.SearchString = cleanedSite.Strip();
                _pHost.Database.RootGroup.SearchEntries(sp, tmpRes);
                tmpResults.Add(tmpRes);
            }

            var results = new PwObjectList <PwEntry>();

            results.Add(tmpResults.Distinct().OrderBy(e => e.Strings.ReadSafe(PwDefs.TitleField)).ToList());

            if (results.UCount == 0)
            {
                return(notFound);
            }

            return(new ResponseData
            {
                Entries = results.Select(e => new ResponseEntry
                {
                    EntryName = e.Strings.ReadSafe(PwDefs.TitleField),
                    Username = e.Strings.ReadSafe(PwDefs.UserNameField),
                    Password = e.Strings.ReadSafe(PwDefs.PasswordField)
                }).ToArray()
            });
        }