//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); }
// Create and initialize a heterogenous array with pwdCheck, compundC and excessC // Return heterogenous array back to calling function // PRE : a random object is already created // a pwdCheck[] variable is declared // POST: state of pwdCheck obj, compundC object and excessC are initialized and set public static pwdCheck[] InitPwdObject(Random rand) { Console.WriteLine(""); Console.WriteLine(ASTERISK + "BEGIN INITIALIZED PWDCLASS OBJECTS" + ASTERISK); int augmentedArraySize = ARR_SIZE * ARR_MULTIPLIER; uint randPwdLength; pwdCheck[] arr_PwdObj = new pwdCheck[augmentedArraySize]; for (int i = 0; i < augmentedArraySize; i++) { if (i < (augmentedArraySize) / ARR_MULTIPLIER) { randPwdLength = (uint)rand.Next(RAND_MIN, RAND_MAX); arr_PwdObj[i] = new pwdCheck(randPwdLength); Console.WriteLine(" Initialized {0} object at index: {1} ", ObjectName.pwdClass, i); Console.WriteLine(" -password length = {0}", arr_PwdObj[i].GetPasswordLength()); Console.WriteLine(" -object status: {0}", (arr_PwdObj[i].IsObjectActive() ? "active" : "inactive")); } else if (i >= (augmentedArraySize / ARR_MULTIPLIER) && i < (augmentedArraySize - ARR_SIZE)) { Console.WriteLine(""); randPwdLength = (uint)rand.Next(RAND_MIN, RAND_MAX); uint toggleCycle = (uint)rand.Next(RAND_MIN, RAND_MAX); arr_PwdObj[i] = new compundC(randPwdLength, toggleCycle); Console.WriteLine(" Initialized {0} object at index: {1} ", ObjectName.compundC, i); Console.WriteLine(" -password length = {0}", randPwdLength); Console.WriteLine(" -toggle cycle = {0}", toggleCycle); Console.WriteLine(" -toggle max = {0}", toggleCycle * ONECYLE * randPwdLength); Console.WriteLine(" -object status: {0}", (arr_PwdObj[i].IsObjectActive() ? "active" : "inactive")); } else { Console.WriteLine(""); bool objStatus = false; randPwdLength = (uint)rand.Next(RAND_MIN, RAND_MAX); arr_PwdObj[i] = new excessC(randPwdLength, objStatus); Console.WriteLine(" Initialized {0} object at index: {1} ", ObjectName.excessC, i); Console.WriteLine(" -password length = {0}", randPwdLength); Console.WriteLine(" -object status: {0}", (objStatus ? "active" : "inactive")); } } Console.WriteLine(ASTERISK + "END INITIALIZED PWDCLASS OBJECTS" + ASTERISK); return(arr_PwdObj); }
//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); }
//Passed a new random generated password for every object in the heterogenous array //Display if the password is valid. //If the password is not valid then state the reason why it failed. //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 TestCheckPassword(pwdCheck[] obj, Random rand) { Console.WriteLine(" "); Console.WriteLine(ASTERISK + "BEGIN TEST PASSWORD" + ASTERISK); int augmentedArraySize = ARR_SIZE * ARR_MULTIPLIER; for (int i = 0; i < augmentedArraySize; i++) { string pWord = GenerateRandomMixedString(rand); if (obj[i] is excessC) { excessC cObj = (excessC)obj[i]; bool exStatus = cObj.exActiveStatus; if (exStatus) { if (cObj.ValidatePassword(pWord)) { Console.WriteLine(" {0} object at index {1} is valid ", ObjectName.excessC, i); Console.WriteLine(" -password '{0}' has an integer at location {1}, " + "has mixed case and has $", pWord, cObj.GetPasswordLength()); Console.WriteLine(" -object status: {0}", exStatus ? "active" : "inactive"); continue; } else { if (pWord.Length >= cObj.GetPasswordLength()) { if (cObj.GetIsInteger()) { if (cObj.GetIsMixedCase()) { Console.WriteLine(" {0} object at index {1} is invalid ", ObjectName.excessC, i); Console.WriteLine(" -password '{0}' doesn't contain dollar sign symbol", pWord); Console.WriteLine(" -object status: {0}", exStatus ? "active" : "inactive"); continue; } else { Console.WriteLine(" {0} object at index {1} is invalid ", ObjectName.excessC, i); Console.WriteLine(" -password '{0}' doesn't contain mixed case", pWord); Console.WriteLine(" -object status: {0}", exStatus ? "active" : "inactive"); continue; } } else { Console.WriteLine(" {0} object at index {1} is invalid ", ObjectName.excessC, i); Console.WriteLine(" -password '{0}' doesn't contain an integer at location {1}", pWord, cObj.GetPasswordLength()); Console.WriteLine(" -object status: {0}", exStatus ? "active" : "inactive"); continue; } } else { Console.WriteLine(" {0} object at index {1} is invalid ", ObjectName.excessC, i); Console.WriteLine(" -password '{0}' doesn't meet length requirement", pWord); Console.WriteLine(" -required length = {0}, password length = {1}", cObj.GetPasswordLength(), pWord.Length); Console.WriteLine(" -object status: {0}", exStatus ? "active" : "inactive"); continue; } } } } if (!obj[i].ValidatePassword(pWord)) { if (obj[i] is compundC) { compundC cObj = (compundC)obj[i]; if (cObj.GetLockedStatus()) { Console.WriteLine(" Object {0} at index {1} is LOCKED ", ObjectName.compundC, i); continue; } } if (obj[i].IsObjectActive()) { if (pWord.Length >= obj[i].GetPasswordLength()) { if (i < (augmentedArraySize) / ARR_MULTIPLIER) { Console.WriteLine(" Object {0} at index {1}'s 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)) { if (obj[i].GetIsCharForbidden()) { Console.WriteLine(" Object {0} at index {1}'s has forbidden character(s) ", ObjectName.compundC, i); Console.WriteLine(" -rejected password '{0}'", pWord); Console.WriteLine(" -object status: {0}", obj[i].IsObjectActive() ? "active" : "inactive"); } else { Console.WriteLine(" Object {0} at index {1} is invalid ", ObjectName.compundC, i); Console.WriteLine(" -there is no repeated character", pWord); Console.WriteLine(" -rejected password '{0}'", pWord); Console.WriteLine(" -object status: {0}", obj[i].IsObjectActive() ? "active" : "inactive"); } } else { Console.WriteLine(" Object {0} at index {1}'s has forbidden character(s)", ObjectName.excessC, i); Console.WriteLine(" -rejected password '{0}'", pWord); Console.WriteLine(" -object status: {0}", obj[i].IsObjectActive() ? "active" : "inactive"); } } else { if (i < (augmentedArraySize) / ARR_MULTIPLIER) { Console.WriteLine(" {0} object at index {1} password is invalid ", ObjectName.pwdClass, i); Console.WriteLine(" -password '{0}' doesn't meet length requirement", pWord); Console.WriteLine(" -required length = {0}, password length = {1}", obj[i].GetPasswordLength(), pWord.Length); 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} is invalid ", ObjectName.compundC, i); Console.WriteLine(" -password '{0}' doesn't meet length requirement", pWord); Console.WriteLine(" -required length = {0}, password length = {1}", obj[i].GetPasswordLength(), pWord.Length); Console.WriteLine(" -object status: {0}", obj[i].IsObjectActive() ? "active" : "inactive"); } else { Console.WriteLine(" {0} object at index {1} is invalid ", ObjectName.excessC, i); Console.WriteLine(" -password '{0}' doesn't meet length requirement", pWord); Console.WriteLine(" -required length = {0}, password length = {1}", obj[i].GetPasswordLength(), pWord.Length); Console.WriteLine(" -object status: {0}", obj[i].IsObjectActive() ? "active" : "inactive"); } } } else { if (i < (augmentedArraySize) / ARR_MULTIPLIER) { Console.WriteLine(" {0} object at index {1} is not active ", ObjectName.pwdClass, i); } else if (i >= (augmentedArraySize / ARR_MULTIPLIER) && i < (augmentedArraySize - ARR_SIZE)) { Console.WriteLine(" {0} object at index {1} is not active ", ObjectName.compundC, i); } else { Console.WriteLine(" {0} object at index {1} is not active", ObjectName.excessC, i); } } } else { if (i < (augmentedArraySize) / ARR_MULTIPLIER) { Console.WriteLine(" {0} object at index {1} password is valid ", ObjectName.pwdClass, i); Console.WriteLine(" -password '{0}' meet requirements", pWord); Console.WriteLine(" -required length = {0}, password length = {1}", obj[i].GetPasswordLength(), pWord.Length); Console.WriteLine(" -contains no forbidden character(s)"); Console.WriteLine(" -object is {0}", obj[i].IsObjectActive() ? "active" : "inactive"); } else if (i >= (augmentedArraySize / ARR_MULTIPLIER) && i < (augmentedArraySize - ARR_SIZE)) { Console.WriteLine(" {0} object at index {1} password is valid ", ObjectName.compundC, i); Console.WriteLine(" -password '{0}' meet requirements", pWord); Console.WriteLine(" -required length = {0}, password length = {1}", obj[i].GetPasswordLength(), pWord.Length); Console.WriteLine(" -contains no forbidden character(s)"); Console.WriteLine(" -contains repeated character(s)"); Console.WriteLine(" -object is {0}", obj[i].IsObjectActive() ? "active" : "inactive"); } else { Console.WriteLine(" {0} object at index {1} is invalid ", ObjectName.excessC, i); Console.WriteLine(" -password '{0}' doesn't meet length requirement", pWord); Console.WriteLine(" -required length = {0}, password length = {1}", obj[i].GetPasswordLength(), pWord.Length); } } } Console.WriteLine(ASTERISK + "END TEST PASSWORD" + ASTERISK); }