var password = ValuePass.Text;
var regex = new Regex(@"([a - z])");
if (password.Length < 8 && regex.IsMatch(password))
{
resultValue.Text = "1 уровень";
return;
}
var regex2 = new Regex(@"([a-zA-Z])");
if (password.Length >= 8 && regex2.IsMatch(password))
{
resultValue.Text = "2 уровень";
return;
}
var regex1 = new Regex(@"([0 - 9])");
if (password.Length >= 8 && regex1.IsMatch(password) && regex2.IsMatch(password))
{
resultValue.Text = "3 уровень";
return;
}
var regex3 = new Regex(@"([!,@,#,$,%,^,&,*,?,_,~])");
if (password.Length >= 8 && regex1.IsMatch(password) && regex2.IsMatch(password) && regex3.IsMatch(password))
{
resultValue.Text = "4 уровень";
return;
}
var password = ValuePass.Text;
var regex = new Regex(@"([a - z])");
var regex2 = new Regex(@"([a-zA-Z])");
var regex1 = new Regex(@"([0 - 9])");
var regex3 = new Regex(@"([!,@,#,$,%,^,&,*,?,_,~])");
if (password.Length >= 8 && regex1.IsMatch(password) && regex2.IsMatch(password) && regex3.IsMatch(password))
{
resultValue.Text = "4 уровень";
return;
}
if (password.Length >= 8 && regex1.IsMatch(password) && regex2.IsMatch(password))
{
resultValue.Text = "3 уровень";
return;
}
if (password.Length >= 8 && regex2.IsMatch(password))
{
resultValue.Text = "2 уровень";
return;
}
if (password.Length < 8 && regex.IsMatch(password))
{
resultValue.Text = "1 уровень";
return;
}
var password = ValuePass.Text;
var regex = new Regex(@"([a - z])");
if (password.Length < 8 && regex.IsMatch(password))
{
resultValue.Text = "1 уровень";
}
var regex2 = new Regex(@"([a-zA-Z])");
if (password.Length >= 8 && regex2.IsMatch(password))
{
resultValue.Text = "2 уровень";
}
var regex1 = new Regex(@"([0 - 9])");
if (password.Length >= 8 && regex1.IsMatch(password) && regex2.IsMatch(password))
{
resultValue.Text = "3 уровень";
}
var regex3 = new Regex(@"([!,@,#,$,%,^,&,*,?,_,~])");
if (password.Length >= 8 && regex1.IsMatch(password) && regex2.IsMatch(password) && regex3.IsMatch(password))
{
resultValue.Text = "4 уровень";
}
return;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var pwd = "Test1236";
var r = new PasswordChecker(pwd);
;
}
}
public class PasswordChecker
{
private readonly char[] _upper = new char[] { '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', };
private readonly char[] _digit = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
private readonly char[] _special = new char[] { '!', '@', '#', '$', '%', '^', '&', '*', '?', '_', '~' };
private readonly int _strongPasswordLength;
private readonly string _password;
public bool IsLengthOk => _password.Length > _strongPasswordLength;
public bool HasUpper { get; private set; }
public bool HasDigit { get; private set; }
public bool HasSpecial { get; private set; }
public PasswordChecker(string password, int passwordLength=8)
{
_password = password;
_strongPasswordLength = passwordLength;
foreach (var ch in _password)
{
HasUpper = _upper.Any(x => x == ch);
HasDigit = _digit.Any(x => x == ch);
HasSpecial = _special.Any(x => x == ch);
}
}
}
}