public static bool ComparePerson(IndividualClass person1, IndividualClass person2, NameEquivalenceDb nameEqDb)
        {
            if (IsNamesEqual(person1.GetName(), person2.GetName(), nameEqDb))
            {
                IndividualEventClass birth1 = person1.GetEvent(IndividualEventClass.EventType.Birth);
                IndividualEventClass birth2 = person2.GetEvent(IndividualEventClass.EventType.Birth);
                IndividualEventClass death1 = person1.GetEvent(IndividualEventClass.EventType.Death);
                IndividualEventClass death2 = person2.GetEvent(IndividualEventClass.EventType.Death);

                DateMatch birthMatch = DateMatch.Unknown, deathMatch = DateMatch.Unknown;

                if ((birth1 != null) && (birth2 != null))
                {
                    birthMatch = MatchDates(birth1.GetDate(), birth2.GetDate());
                }
                if ((death1 != null) && (death2 != null))
                {
                    deathMatch = MatchDates(death1.GetDate(), death2.GetDate());
                }
                if ((birthMatch == DateMatch.Unknown) && (deathMatch == DateMatch.Unknown))
                {
                    return(false);
                }
                if ((birthMatch == DateMatch.Bad) || (deathMatch == DateMatch.Bad))
                {
                    return(false);
                }
                return((birthMatch == DateMatch.Good) || (deathMatch == DateMatch.Good));
            }
            return(false);
        }
Exemple #2
0
        private static double DateGuesses(Match match)
        {
            DateMatch dm        = (DateMatch)match;
            double    yearSpace = Math.Max(Math.Abs(dm.Year - REFERENCE_YEAR), MIN_YEAR_SPACE);
            double    guesses   = yearSpace * 365;

            if (dm.Separator.Length > 0)
            {
                guesses *= 4;
            }
            return(guesses);
        }
        /// <summary>
        /// Estimates the attempts required to guess the password.
        /// </summary>
        /// <param name="match">The match.</param>
        /// <returns>The guesses estimate.</returns>
        public static double CalculateGuesses(DateMatch match)
        {
            var yearSpace = Math.Max(Math.Abs(match.Year - DateMatcher.ReferenceYear), MinimumYearSpace);

            var guesses = yearSpace * 365.0;

            if (!string.IsNullOrEmpty(match.Separator))
            {
                guesses *= 4;
            }

            return(guesses);
        }
Exemple #4
0
        public void MultipliesByFourForSeparators()
        {
            var match = new DateMatch
            {
                Token     = "1923",
                Separator = "/",
                Year      = 1923,
                Month     = 1,
                Day       = 1,
                i         = 1,
                j         = 2,
            };

            var actual   = DateGuessesCalculator.CalculateGuesses(match);
            var expected = 365 * (DateMatcher.ReferenceYear - match.Year) * 4;

            actual.Should().Be(expected);
        }
Exemple #5
0
        public void IsDelegatedToBeEstimateGuesses()
        {
            var match = new DateMatch
            {
                Token     = "1923",
                Separator = string.Empty,
                Year      = 1923,
                Month     = 1,
                Day       = 1,
                i         = 1,
                j         = 2,
            };

            var actual   = PasswordScoring.EstimateGuesses(match, "1923");
            var expected = 365 * (DateMatcher.ReferenceYear - match.Year);

            actual.Should().Be(expected);
        }
Exemple #6
0
        public void CalculatesBasedOnReferenceYear()
        {
            var match = new DateMatch
            {
                Token     = "1923",
                Separator = string.Empty,
                Year      = 1923,
                Month     = 1,
                Day       = 1,
                i         = 1,
                j         = 2,
            };

            var actual   = DateGuessesCalculator.CalculateGuesses(match);
            var expected = 365 * (DateMatcher.ReferenceYear - match.Year);

            actual.Should().Be(expected);
        }
Exemple #7
0
        public void AssumesMinYearSpaceForRecentYears()
        {
            var match = new DateMatch
            {
                Token     = "2010",
                Separator = string.Empty,
                Year      = 2010,
                Month     = 1,
                Day       = 1,
                i         = 1,
                j         = 2,
            };

            var actual   = DateGuessesCalculator.CalculateGuesses(match);
            var expected = 365 * DateGuessesCalculator.MinimumYearSpace;

            actual.Should().Be(expected);
        }
Exemple #8
0
        public void ReturnsCachedGuessesIfAvailable()
        {
            var match = new DateMatch
            {
                Guesses   = 1,
                Token     = "1977",
                Year      = 1977,
                Month     = 8,
                Day       = 14,
                Separator = "/",
                i         = 1,
                j         = 2,
            };

            var actual = PasswordScoring.EstimateGuesses(match, string.Empty);

            actual.Should().Be(1);
        }
Exemple #9
0
 public int CompareTo(Match other)
 {
     return(DateMatch.CompareTo(other.DateMatch));
 }