Esempio n. 1
0
        public void TestPasswordType()
        {
            PasswordValidationRule passVR      = new PasswordValidationRule();
            CultureInfo            cultureInfo = new CultureInfo("ru-RU");

            Assert.IsInstanceOfType(passVR.Validate("Root123", cultureInfo), typeof(ValidationResult));
        }
        public void PasswordValidationReturnsFalse(string password)
        {
            PasswordValidationRule passwordValidationRule = new PasswordValidationRule(password);
            bool expected = false;
            bool actual   = passwordValidationRule.Validate();

            Assert.AreEqual(expected, actual);
        }
Esempio n. 3
0
        public void TestBadPassword()
        {
            PasswordValidationRule passVR      = new PasswordValidationRule();
            CultureInfo            cultureInfo = new CultureInfo("ru-RU");
            var actual   = passVR.Validate("rot", cultureInfo);
            var expected = new ValidationResult(false, "Пароль должен содержать:\nХотя бы одно число\nХотя бы одну латинскую букву в верхнем и нижнем регистре\nСтрока не менее 6 символов");

            Assert.AreEqual(expected, actual);
        }
Esempio n. 4
0
        public void TestGoodPassword()
        {
            PasswordValidationRule passVR      = new PasswordValidationRule();
            CultureInfo            cultureInfo = new CultureInfo("ru-RU");
            var actual   = passVR.Validate("Root123", cultureInfo);
            var expected = new ValidationResult(false, null);

            Assert.AreNotEqual(expected, actual);
        }
Esempio n. 5
0
        public void TestPasswordRegex_False()
        {
            // arrange
            var passwordValidationRule = new PasswordValidationRule();
            // act
            var result = passwordValidationRule.Validate("Test12", CultureInfo.CurrentCulture);

            // assert
            Assert.IsFalse(result.IsValid);
        }
Esempio n. 6
0
        private void DoLogin(object commandArg)
        {
            SetLoginState(true);

            LoginInfoArgs infoArgs = commandArg as LoginInfoArgs;

            bool bValidated = true;

            if (!AccountValidationRule.Validate(infoArgs.AccountControl.Text))
            {
                _eventAggregator.GetEvent <InputErrorEvent>().Publish(new InputErrorEventArgs(InputErrorKinds.Account));
                bValidated = false;
            }

//#if DEBUG
            if (!PasswordValidationRule.Validate(infoArgs.PasswordControl.Password))
//#else
//            if (!PasswordValidationRule.Validate(infoArgs.PasswordControl.SecurePassword))
//#endif
            {
                _eventAggregator.GetEvent <InputErrorEvent>().Publish(new InputErrorEventArgs(InputErrorKinds.Password));
                bValidated = false;
            }

            if (bValidated)
            {
                try
                {
#if DEBUG
                    LoginInfo info = new LoginInfo(infoArgs.AccountControl.Text, infoArgs.PasswordControl.Password, infoArgs.IP);
#else
                    LoginInfo info = new LoginInfo(infoArgs.AccountControl.Text, infoArgs.PasswordControl.SecurePassword, infoArgs.IP);
#endif
                    _lighterContext.AccountLogin(info, new InstanceContext(_loginCallback));
                }
                catch (ServerClosedException ex)
                {
                    SetLoginMessage(ex.Message);
                    _eventAggregator.GetEvent <ServiceEvent>().Publish(new ServiceEventArgs(ServiceEventKind.Closed, ex.Message));
                }
                catch (ServerNotFoundException ex)
                {
                    SetLoginMessage(ex.Message);

                    _eventAggregator.GetEvent <ServiceEvent>().Publish(new ServiceEventArgs(ServiceEventKind.NotFound, ex.Message));
                }
                catch (ServerTooBusyException ex)
                {
                    SetLoginMessage(ex.Message);
                    _eventAggregator.GetEvent <ServiceEvent>().Publish(new ServiceEventArgs(ServiceEventKind.TooBusy, ex.Message));
                }
            }

            SetLoginState(false);
        }
Esempio n. 7
0
        public bool Validate()
        {
            var validationResult = true;

            var emailValidation    = new EmailValidationRule();
            var loginValidation    = new LoginValidationRule();
            var passwordValidation = new PasswordValidationRule();

            validationResult &= emailValidation.Validate(Email, null).IsValid;
            validationResult &= loginValidation.Validate(Login, null).IsValid;
            validationResult &= passwordValidation.Validate(Password, null).IsValid;

            return(validationResult);
        }
Esempio n. 8
0
        private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
        {
            var validationResult  = m_PasswordValidationRule.Validate(m_PasswordBox.Password, null);
            var bindingExpression = m_PasswordBox.GetBindingExpression(PasswordBox.PasswordCharProperty);

            if (validationResult.IsValid)
            {
                m_RegisterViewModel.Password = m_PasswordBox.SecurePassword;
                Validation.ClearInvalid(bindingExpression);
            }
            else
            {
                var validationError = new ValidationError(m_PasswordValidationRule, bindingExpression, validationResult.ErrorContent, null);
                Validation.MarkInvalid(bindingExpression, validationError);
            }

            ConfirmPasswordBox_PasswordChanged(sender, e);
        }