12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text.RegularExpressions;
- using Microsoft.EntityFrameworkCore;
- using ReactiveUI;
- using RegAuth.Models;
- namespace RegAuth.ViewModels
- {
- internal class validViewModel : ViewModelBase
- {
- List<User> _listUsers;
- public List<User> SortUsers { get => _listUsers; set => this.RaiseAndSetIfChanged(ref _listUsers, value); }
- public string NameValidate(string name)
- {
- SortUsers = MainWindowViewModel.myConnection.Users.Where(u => u.Login == name).ToList();
- if (string.IsNullOrEmpty(name))
- {
- return "Çàïîëíèòå ëîãèí";
- }
- if (SortUsers.Any())
- {
- return "Ëîãèí çàðåçåðâèðîâàí äðóãèì ïîëüçîâàòåëåì.";
- }
- return string.Empty;
- }
- public string ValidatePassword(string password)
- {
- if (string.IsNullOrEmpty(password))
- {
- return "Ïàðîëü íå ìîæåò áûòü ïóñòûì.";
- }
- if (char.IsDigit(password[0]))
- {
- return "Ïàðîëü íå äîëæåí íà÷èíàòüñÿ ñ öèôðû.";
- }
- int upperCaseCount = Regex.Matches(password, "[A-Z]").Count;
- int lowerCaseCount = Regex.Matches(password, "[a-z]").Count;
- int digitCount = Regex.Matches(password, "[0-9]").Count;
- if (upperCaseCount < 2)
- {
- return "Ïàðîëü äîëæåí ñîäåðæàòü íå ìåíåå 2 çàãëàâíûõ ëàòèíñêèõ ñèìâîëîâ.";
- }
- if (lowerCaseCount < 3)
- {
- return "Ïàðîëü äîëæåí ñîäåðæàòü íå ìåíåå 3 ñòðî÷íûõ ëàòèíñêèõ ñèìâîëîâ.";
- }
- if (digitCount < 2)
- {
- return "Ïàðîëü äîëæåí ñîäåðæàòü íå ìåíåå 2 öèôð.";
- }
- if (password.Length < 8)
- {
- return "Ïàðîëü äîëæåí ñîäåðæàòü íå ìåíåå 8 ñèìâîëîâ.";
- }
- return string.Empty; // Åñëè îøèáîê íåò
- }
- }
- }
|