The main condition is that the password was at least one digit, letter, and special symbol. I do not know how you can check this:

Random random = new Random(); List<string> letters = new List<string> {"a","b","c","d","e","f","g","h","i","j","k", "l","m","n","o","p","q","r","s","t","u","v", "w","x","y","z","A","B","C","D","e","f", "G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; List<int> numbers = new List<int> {0,1,2,3,4,5,6,7,8,9}; List<string> specialSymbols = new List<string> {"!","@","#","â„–","$","%","^","&","*","-","_", "?","<",">"}; List<string> newNumbers = numbers.Select(x => x.ToString()).ToList(); var summaryList = letters.Concat(newNumbers).Concat(specialSymbols); IEnumerable<string> list = summaryList.OrderBy(x => random.Next()).Take(10); Console.Write("List<string> with letters: "); foreach (var element in letters) { Console.Write(element); } Console.Write("List<int> with numbers converted to string: "); foreach (var element in newNumbers) { Console.Write(element); } Console.WriteLine(); Console.Write("List<string> with special symbols: "); foreach (var element in specialSymbols) { Console.Write(element); } Console.WriteLine(); string password = ""; Console.Write("Summary List<string> which contains 15 random characters for generating new password: "); foreach (var element in list) { password += element; } Console.Write(password); Console.ReadKey(); 

I ask you to give an answer easier, preferably, since I am still green in this matter. Thank)

  • one
    Not quite clear about the autotest in the subject. What is the problem? Generate such a password or write a code that would check the password for correctness? - newman
  • ((?=.*\\d)(?=.*[az])(?=.*[AZ])(?=.*[@#$%]).{6,20}) through the regular course is easier to do - Senior Pomidor
  • Password generation is one thing, and it can be made simpler than yours, and at the same time valid passwords. Checking the password for compliance with the requirements is completely different, it can be done differently, depending on the final requirements. - rdorn

0