public void CswRandomStringComplexAll_UnitTest() { bool AllPass = true; for (int i = 0; i < 100000; i += 1) { string RdmStr = CswRandom.RandomString(); //All strings are 12 characters and has a letter, a number, and a special char AllPass = RdmStr.Length == 12 && AllPass && CswTools.HasAlpha(RdmStr) && CswTools.HasNumber(RdmStr) && CswTools.HasSpecialCharacter(RdmStr); } Assert.IsTrue(AllPass, "Not all strings met the complexity requirements."); }
private string _validatePassword(string NewPassword) { if (string.IsNullOrEmpty(NewPassword)) { throw new CswDniException(CswEnumErrorType.Warning, "Passwords cannot be empty.", "The supplied password was null or empty."); } string Ret = NewPassword.Trim(); if (string.IsNullOrEmpty(Ret)) { throw new CswDniException(CswEnumErrorType.Warning, "Passwords cannot be empty.", "The supplied password was null or empty."); } if (_CswNbtResources.ConfigVbls.doesConfigVarExist(ChemSW.Config.CswEnumConfigurationVariableNames.Password_Length)) { Int32 Length = CswConvert.ToInt32(_CswNbtResources.ConfigVbls.getConfigVariableValue(ChemSW.Config.CswEnumConfigurationVariableNames.Password_Length)); if (Ret.Length < Length) { throw new CswDniException(CswEnumErrorType.Warning, "Passwords must be at least " + Length + " characters long.", "The supplied password was not long enough."); } } if (_CswNbtResources.ConfigVbls.doesConfigVarExist(ChemSW.Config.CswEnumConfigurationVariableNames.Password_Complexity)) { Int32 ComplexityLevel = CswConvert.ToInt32(_CswNbtResources.ConfigVbls.getConfigVariableValue(ChemSW.Config.CswEnumConfigurationVariableNames.Password_Complexity)); if (ComplexityLevel > 0) { if (false == CswTools.HasAlpha(Ret) || false == CswTools.HasNumber(Ret)) { throw new CswDniException(CswEnumErrorType.Warning, "Password complexity requires that passwords contain at least 1 number and 1 letter.", "The supplied password did not contain both a letter and a number."); } if (ComplexityLevel > 1) { if (false == CswTools.HasSpecialCharacter(Ret)) { throw new CswDniException(CswEnumErrorType.Warning, "Password complexity requires that passwords contain at least 1 special character.", "The supplied password contained only alphanumeric characters."); } } } } //ensure that the password hasn't been used recently if (PreviouslyUsedPasswords.IndexOf(_CswEncryption.getMd5Hash(Ret)) > -1) { throw new CswDniException(CswEnumErrorType.Warning, "You may not reuse the same password so soon.", "The supplied password appears in your " + _CswNbtResources.ConfigVbls.getConfigVariableValue(CswEnumNbtConfigurationVariables.password_reuse_count.ToString()) + " most recently used passwords."); } return(Ret); }
public void CswRandomStringComplexAlpha_UnitTest() { bool AllPass = true; for (int i = 0; i < 100000; i += 1) { string RdmStr = CswRandom.RandomString(new CswRandom.Config { IncludeLetters = true, IncludeNumbers = false, IncludeSymbols = false, Length = 9 }); //All strings are 9 characters, none has a special character or a number, and all have letters AllPass = AllPass && RdmStr.Length == 9 && false == CswTools.HasSpecialCharacter(RdmStr) && false == CswTools.HasNumber(RdmStr) && CswTools.HasAlpha(RdmStr); } Assert.IsTrue(AllPass, "Not all strings met the complexity requirements."); }