12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Text.RegularExpressions;
- using ReactiveUI;
- namespace RegAuth.ViewModels
- {
- internal class validViewModel : ViewModelBase
- {
- //public bool IsValidPassword(string password)
- //{
- // // Ïðîâåðêà, ÷òî ïàðîëü íå íà÷èíàåòñÿ ñ öèôðû
- // if (string.IsNullOrEmpty(password) || char.IsDigit(password[0]))
- // {
- // return false;
- // }
- // // Ðåãóëÿðíîå âûðàæåíèå äëÿ ïðîâåðêè òðåáîâàíèé ê ïàðîëþ
- // string pattern = @"^(?=(?:[^A-Z]*[A-Z]){2})(?=(?:[^a-z]*[a-z]){3})(?=(?:[^0-9]*[0-9]){2})[A-Za-z0-9]{8,}$";
- // return Regex.IsMatch(password, pattern);
- //}
- 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; // Åñëè îøèáîê íåò
- }
- }
- }
|