public static string GetSymbols(this SymbolsType type) { var resultSymbols = string.Empty; foreach (var typeFlag in type.GetFlags()) { switch (typeFlag) { case SymbolsType.LowcaseLatin: resultSymbols += LowcaseLatinSymbols; break; case SymbolsType.UpcaseLatin: resultSymbols += UpcaseLatinSymbols; break; case SymbolsType.Digital: resultSymbols += NumberSymbols; break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } } Contract.Assume(resultSymbols != null); return(resultSymbols); }
private static string GenerateMandatoryPart( SymbolsType acceptedTypes, byte[] passwordSymbolsNumbers) { var passwordPartBuilder = new StringBuilder(); for (var i = 0; acceptedTypes != 0; i++) { var randomTypeNumber = passwordSymbolsNumbers[2 * i]; var randomSymbolNumber = passwordSymbolsNumbers[2 * i + 1]; var unusedTypes = acceptedTypes.GetFlags().ToArray(); var usedType = unusedTypes[randomTypeNumber % unusedTypes.Length]; var usedSymbols = usedType.GetSymbols(); passwordPartBuilder.Append(usedSymbols[randomSymbolNumber % usedSymbols.Length]); acceptedTypes = TurnOffFlag(acceptedTypes, usedType); } return passwordPartBuilder.ToString(); }
private static string GenerateMandatoryPart( SymbolsType acceptedTypes, byte[] passwordSymbolsNumbers) { var passwordPartBuilder = new StringBuilder(); for (var i = 0; acceptedTypes != 0; i++) { var randomTypeNumber = passwordSymbolsNumbers[2 * i]; var randomSymbolNumber = passwordSymbolsNumbers[2 * i + 1]; var unusedTypes = acceptedTypes.GetFlags().ToArray(); var usedType = unusedTypes[randomTypeNumber % unusedTypes.Length]; var usedSymbols = usedType.GetSymbols(); passwordPartBuilder.Append(usedSymbols[randomSymbolNumber % usedSymbols.Length]); acceptedTypes = TurnOffFlag(acceptedTypes, usedType); } return(passwordPartBuilder.ToString()); }