Пример #1
0
        public static bool IsPasswordValidB(PasswordModel pModel)
        {
            bool isValid   = false;
            int  firstPos  = pModel.FirstPosition;
            int  secondPos = pModel.SecondPosition;

            if (pModel.Password[firstPos] == pModel.RequiredLetter && pModel.Password[secondPos] == pModel.RequiredLetter)
            {
                isValid = false;
            }
            else if (pModel.Password[firstPos] == pModel.RequiredLetter || pModel.Password[secondPos] == pModel.RequiredLetter)
            {
                isValid = true;
            }

            return(isValid);
        }
Пример #2
0
        /// <summary>
        /// This method is responsible for handling the second assignment.
        /// </summary>
        /// <param name="passwordManager"></param>
        /// <returns>The amount of valid passwords.</returns>

        public int StartSecondAssignment(PasswordManager passwordManager)
        {
            string[] passwords = passwordManager.GetPasswords();
            int      amountOfValidPasswords = 0;

            foreach (var pwd in passwords)
            {
                string[]      pwdString = passwordManager.SplitPasswordString(pwd);
                PasswordModel pModel    = new PasswordModel(Convert.ToInt32(pwdString[0]), Convert.ToInt32(pwdString[1]), Convert.ToChar(pwdString[2]), pwdString[3]);
                pModel.IsValid = PasswordModel.IsPasswordValidB(pModel);
                if (pModel.IsValid)
                {
                    amountOfValidPasswords++;
                }
            }

            return(amountOfValidPasswords);
        }
Пример #3
0
        public static bool IsPasswordValidA(PasswordModel pModel)
        {
            int occurenceOfLetter = pModel.Password.Count(t => t == pModel.RequiredLetter);

            return(occurenceOfLetter >= pModel.MinimalOccurence && occurenceOfLetter <= pModel.MaximumOccurence);
        }