ValidViewModel.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6. using Microsoft.EntityFrameworkCore;
  7. using ReactiveUI;
  8. using RegAuth.Models;
  9. namespace RegAuth.ViewModels
  10. {
  11. internal class validViewModel : ViewModelBase
  12. {
  13. List<User> _listUsers;
  14. public List<User> SortUsers { get => _listUsers; set => this.RaiseAndSetIfChanged(ref _listUsers, value); }
  15. public string NameValidate(string name)
  16. {
  17. SortUsers = MainWindowViewModel.myConnection.Users.Where(u => u.Login == name).ToList();
  18. if (string.IsNullOrEmpty(name))
  19. {
  20. return "Çàïîëíèòå ëîãèí";
  21. }
  22. if (SortUsers.Any())
  23. {
  24. return "Ëîãèí çàðåçåðâèðîâàí äðóãèì ïîëüçîâàòåëåì.";
  25. }
  26. return string.Empty;
  27. }
  28. public string ValidatePassword(string password)
  29. {
  30. if (string.IsNullOrEmpty(password))
  31. {
  32. return "Ïàðîëü íå ìîæåò áûòü ïóñòûì.";
  33. }
  34. if (char.IsDigit(password[0]))
  35. {
  36. return "Ïàðîëü íå äîëæåí íà÷èíàòüñÿ ñ öèôðû.";
  37. }
  38. int upperCaseCount = Regex.Matches(password, "[A-Z]").Count;
  39. int lowerCaseCount = Regex.Matches(password, "[a-z]").Count;
  40. int digitCount = Regex.Matches(password, "[0-9]").Count;
  41. if (upperCaseCount < 2)
  42. {
  43. return "Ïàðîëü äîëæåí ñîäåðæàòü íå ìåíåå 2 çàãëàâíûõ ëàòèíñêèõ ñèìâîëîâ.";
  44. }
  45. if (lowerCaseCount < 3)
  46. {
  47. return "Ïàðîëü äîëæåí ñîäåðæàòü íå ìåíåå 3 ñòðî÷íûõ ëàòèíñêèõ ñèìâîëîâ.";
  48. }
  49. if (digitCount < 2)
  50. {
  51. return "Ïàðîëü äîëæåí ñîäåðæàòü íå ìåíåå 2 öèôð.";
  52. }
  53. if (password.Length < 8)
  54. {
  55. return "Ïàðîëü äîëæåí ñîäåðæàòü íå ìåíåå 8 ñèìâîëîâ.";
  56. }
  57. return string.Empty; // Åñëè îøèáîê íåò
  58. }
  59. }
  60. }