petarkobakov

Registration

Aug 3rd, 2020 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace Registration
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int registrations = int.Parse(Console.ReadLine());
  11. string pattern = @"(U\$)(?<username>[A-Z]{1}[a-z]{2,})(\1)(P\@\$)(?<password>[A-Za-z]{5,}[0-9]+)(\3)";
  12.  
  13. int successfulRegistrationsCount = 0;
  14.  
  15. for (int i = 0; i < registrations; i++)
  16. {
  17. string input = Console.ReadLine();
  18. Match valid = Regex.Match(input,pattern);
  19.  
  20. if (valid.Success)
  21. {
  22. successfulRegistrationsCount++;
  23.  
  24. Console.WriteLine("Registration was successful");
  25. Console.WriteLine($"Username: {valid.Groups["username"].Value}, Password: {valid.Groups["password"].Value}");
  26.  
  27. }
  28.  
  29. else
  30. {
  31. Console.WriteLine($"Invalid username or password");
  32.  
  33. }
  34. }
  35.  
  36. Console.WriteLine($"Successful registrations: {successfulRegistrationsCount}");
  37. }
  38. }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment