private void generateSimplePass(object obj) { int size; if (Int32.TryParse(Password_OBJ.Length, out size)) { if (size > 45) { Password_OBJ.OutputtringInSimple = "The maximum size ot password is 45"; return; } PassModel model = new PassModel(); ObservableCollection <string> alllines = model.GetData(); foreach (string line in alllines) { if (size > line.Length) { int sizepass = size - line.Length; String addpass = Password_OBJ.generatesimple(sizepass, sumbols + numbers); String newpass = line + addpass; Password_OBJ.OutputtringInSimple = newpass; } } } else { Password_OBJ.OutputtringInSimple = "YOU HAVE TO ENTER A VALID LENGHT OF A PASSWORD"; } }
private void genereteAPass(object obj) { StringBuilder pass = new StringBuilder(); int size; string symbols; if (String.IsNullOrEmpty(Password_OBJ.Length)) { Password_OBJ.Outputtring = "The size is not entered"; return; } if (string.IsNullOrEmpty(Password_OBJ.Exclude)) { symbols = ""; } else { symbols = Password_OBJ.Exclude; } if (Int32.TryParse(Password_OBJ.Length, out size)) { if (size > 45) { Password_OBJ.Outputtring = "The maximum size ot password is 45"; return; } StringBuilder possiblecharecters = new StringBuilder(); Random random = new Random(); bool CheckSymbols = Password_OBJ.IsCheckedSymbol; bool CheckNumbers = Password_OBJ.IsCheckedNumbers; bool CheckLowerCase = Password_OBJ.IsCheckedLowerCase; bool CheckUpperCase = Password_OBJ.IsCheckedUpperCase; if (CheckSymbols) { String possiblesymbols = removesymbols(symbols, sumbols); if (String.IsNullOrEmpty(possiblesymbols)) { Password_OBJ.Outputtring = "Have to remove Symbols from excluded textfiled to be included in password"; return; } int Symbol = random.Next(0, possiblesymbols.Length); char sym = possiblesymbols[Symbol]; pass.Append(sym); possiblecharecters.Append(possiblesymbols); } if (CheckNumbers) { String possiblenumbers = removesymbols(symbols, numbers); if (String.IsNullOrEmpty(possiblenumbers)) { Password_OBJ.Outputtring = "Have remove Numbers from excluded textfiled to be included in password"; return; } int Symbol = random.Next(0, possiblenumbers.Length); char sym = possiblenumbers[Symbol]; pass.Append(sym); possiblecharecters.Append(possiblenumbers); } if (CheckLowerCase) { String possibleLowerCase = removesymbols(symbols, lowercase); if (String.IsNullOrEmpty(possibleLowerCase)) { Password_OBJ.Outputtring = "Have to remove Lower Case Letters from excluded textfiled to be included in password"; return; } int Symbol = random.Next(0, possibleLowerCase.Length); char sym = possibleLowerCase[Symbol]; pass.Append(sym); possiblecharecters.Append(possibleLowerCase); } if (CheckUpperCase) { String possibleUpperCase = removesymbols(symbols, uppercase); if (String.IsNullOrEmpty(possibleUpperCase)) { Password_OBJ.Outputtring = "Have to remove Upper Case Letters from excluded textfiled to be included in password"; return; } int Symbol = random.Next(0, uppercase.Length); char sym = possibleUpperCase[Symbol]; pass.Append(sym); possiblecharecters.Append(possibleUpperCase); } if (String.IsNullOrEmpty(possiblecharecters.ToString())) { Password_OBJ.Outputtring = "No one criteria is choosen"; return; } int leftsize = size - pass.Length; String possible = possiblecharecters.ToString(); String additional = Password_OBJ.GeneretePass(leftsize, possible); String finalpass = pass.ToString() + additional; String Finalpass = Shuffle(finalpass); Password_OBJ.Outputtring = finalpass; } else { Password_OBJ.Outputtring = "YOU HAVE TO ENTER A VALID LENGHT OF A PASSWORD"; return; } }