예제 #1
0
        //Passed a new random generated password for every object in the heterogenous array
        //Update the forbidden characters in the pwdClass.
        //Expected to see password failed validation
        //Display the failed validation reason
        //PRE : pwdCheck, compundC and excessC are already initialized
        //      All data members are initialized
        //POST: pwdCheck, compundC and excessC objects may changed state
        public static void TestForbiddenCharsInPwd(pwdCheck[] obj, Random rand, string strForbidden)
        {
            char[] cForbidden = strForbidden.ToCharArray();
            Console.WriteLine(" ");
            Console.WriteLine(ASTERISK + "BEGIN TEST PASSWORD WITH UPDATED FORBIDDEN CHARACTERS" + ASTERISK);
            Console.WriteLine("Non ASCII forbidden characters = {0}", strForbidden);

            int augmentedArraySize = ARR_SIZE * ARR_MULTIPLIER;

            for (int i = 0; i < augmentedArraySize; i++)
            {
                int    pwdLength = obj[i].GetPasswordLength();
                string pWord     = GenRandStrWithPredefinedLen(rand, pwdLength);
                obj[i].SetForbiddenCharacters(cForbidden);
                if (!obj[i].ValidatePassword(pWord))
                {
                    if (obj[i].IsObjectActive())
                    {
                        if (pWord.Length >= obj[i].GetPasswordLength())
                        {
                            if (i < (augmentedArraySize) / ARR_MULTIPLIER)
                            {
                                Console.WriteLine(" {0} object at index {1} has forbidden character(s) ", ObjectName.pwdClass, i);
                                Console.WriteLine(" -rejected password '{0}'", pWord);
                                Console.WriteLine(" -object status: {0}", obj[i].IsObjectActive() ? "active" : "inactive");
                            }
                            else if (i >= (augmentedArraySize / ARR_MULTIPLIER) && i < (augmentedArraySize - ARR_SIZE))
                            {
                                Console.WriteLine(" {0} object at index {1} has forbidden character(s) ", ObjectName.compundC, i);
                                Console.WriteLine(" -rejected password '{0}'", pWord);
                                Console.WriteLine(" -object status: {0}", obj[i].IsObjectActive() ? "active" : "inactive");
                            }
                            else
                            {
                                if (obj[i] is excessC)
                                {
                                    excessC c = (excessC)obj[i];
                                    Console.WriteLine(" {0} object at index {1} has forbidden character(s)", ObjectName.excessC, i);
                                    Console.WriteLine(" -rejected password '{0}'", pWord);
                                    Console.WriteLine(" -object status: {0}", c.GetExObjectStatus() ? "active" : "inactive");
                                }
                            }
                        }
                    }
                }
            }
            Console.WriteLine(ASTERISK + "END TEST PASSWORD WITH UPDATED FORBIDDEN CHARACTERS" + ASTERISK);
        }
예제 #2
0
        //Toggled compundC state until it's LOCKED
        //Toggled pwdCheck and execessC objects
        //PRE : pwdCheck, compundC and excessC are already initialized
        //      All data members are initialized
        //      Some of the object may have already changed state
        //      compundC may already been LOCKED
        //POST: pwdCheck will changed state
        //      compundC state will be changed to LOCKed if it hasn't already
        //      excessC will be toggled if it's state is 'OFF'
        public static void TestToggleObject(pwdCheck[] obj, Random rand)
        {
            Console.WriteLine(" ");
            Console.WriteLine(ASTERISK + "BEGIN TEST TOGGLE OBJECTS" + ASTERISK);
            int    augmentedArraySize = ARR_SIZE * ARR_MULTIPLIER;
            string pWord;

            for (int i = 0; i < augmentedArraySize; i++)
            {
                if (i < (augmentedArraySize) / ARR_MULTIPLIER)
                {
                    bool pStatus     = obj[i].IsObjectActive();
                    int  pToggledMax = obj[i].GetPasswordLength();
                    while (pStatus == obj[i].IsObjectActive())
                    {
                        pWord = GenerateRandomMixedString(rand);
                        obj[i].ValidatePassword(pWord);
                    }

                    Console.WriteLine(" Object {0} at index {1} was toggled ", ObjectName.pwdClass, i);
                    Console.WriteLine(" -toggled at {0} requests.", pToggledMax);
                    Console.WriteLine(" -updated status: {0}.", (obj[i].IsObjectActive() ? "active" : "inactive"));
                }
                else if (i >= (augmentedArraySize / ARR_MULTIPLIER) && i < (augmentedArraySize - ARR_SIZE))
                {
                    if (obj[i] is compundC)
                    {
                        compundC cObj        = (compundC)obj[i];
                        int      countToggle = 0;
                        if (cObj.GetLockedStatus())
                        {
                            Console.WriteLine(" Object {0} at index  {1} have been LOCKED", ObjectName.compundC, i);
                            continue;
                        }
                        else
                        {
                            while (!cObj.GetLockedStatus())
                            {
                                countToggle++;
                                pWord = GenerateRandomMixedString(rand);
                                obj[i].ValidatePassword(pWord);
                            }
                            Console.WriteLine(" Object {0} at index {1} is LOCKED", ObjectName.compundC, i);
                            Console.WriteLine(" -locked at {0} toggles", countToggle);
                            continue;
                        }
                    }
                }
                else
                {
                    if (obj[i] is excessC)
                    {
                        excessC cObj       = (excessC)obj[i];
                        bool    exStatusOn = cObj.GetExObjectStatus();
                        if (exStatusOn)
                        {
                            Console.WriteLine(" Object {0} at index {1} is {2} ", ObjectName.excessC, i,
                                              (cObj.GetExObjectStatus() ? "active" : "inactive"));
                            Console.WriteLine(" -by design when object status is {0}", (exStatusOn ? "active" : "inactive"));
                            Console.WriteLine(" -object state can't be toggled");
                        }
                        else
                        {
                            bool exStatusOff = obj[i].IsObjectActive();
                            int  cToggledMax = obj[i].GetPasswordLength();
                            while (exStatusOff == obj[i].IsObjectActive())
                            {
                                pWord = GenerateRandomMixedString(rand);
                                obj[i].ValidatePassword(pWord);
                            }
                            Console.WriteLine(" Object {0} at index: {1} was toggled ", ObjectName.excessC, i);
                            Console.WriteLine(" -toggled at {0} requests.", cToggledMax);
                            Console.WriteLine(" -status: {0}.", (exStatusOn ? "active" : "inactive"));
                        }
                    }
                }
            }

            Console.WriteLine(ASTERISK + "END TEST TOGGLE OBJECTS" + ASTERISK);
        }