Ejemplo n.º 1
0
        public void CorrectPassword()
        {
            BoardGameDatabase.Interfaces.Validators.IPasswordValidation validPassword = new PasswordValidation();

            string password8symbols  = "Bksai1@0";
            string passwordOk        = "hasLo876!";
            string password16symbols = "SupeRTa1jn>>Pa$$";

            var result1 = validPassword.Validate(password8symbols);
            var result2 = validPassword.Validate(passwordOk);
            var result3 = validPassword.Validate(password16symbols);

            Assert.AreEqual(result1.IsSucces, true);
            Assert.AreEqual(result2.IsSucces, true);
            Assert.AreEqual(result3.IsSucces, true);
        }
Ejemplo n.º 2
0
        private void ConfirmPasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
        {
            var isEqual = string.Equals(PasswordBox.Password, ConfirmPasswordBox.Password);

            if (DataContext != null)
            {
                ((AuthViewModel)DataContext).ConfirmPasswordValidate =
                    PasswordValidation.Validate(ConfirmPasswordBox.Password, isEqual) !.resourceValue;
            }

            ConfirmPasswordValidateBlock.Visibility =
                ConfirmPasswordValidateBlock.Text == App.GetResourceValue("MbPasswordSuccess")
                                        ? Visibility.Collapsed
                                        : Visibility.Visible;

            if (DataContext != null)
            {
                ((AuthViewModel)DataContext).IsPasswordCorrect =
                    PasswordValidation.Compare(((PasswordBox)sender).SecurePassword, PasswordBox.SecurePassword) &&
                    ((AuthViewModel)DataContext).ConfirmPasswordValidate == App.GetResourceValue("MbPasswordSuccess");
            }

            if (PasswordBox.Password == ConfirmPasswordBox.Password)
            {
                PasswordValidateBlock.Visibility        = Visibility.Collapsed;
                ConfirmPasswordValidateBlock.Visibility = Visibility.Collapsed;
            }
        }
Ejemplo n.º 3
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            IDValidation validator = new IDValidation();

            if (validator.ValidateID(this.textboxID.Text))
            {
                MessageBox.Show("Valid ID.");
                ID id = new ID(textboxID.Text);
                id.ParseID();
                MessageBox.Show(id.GetIdType() + "");

                PasswordValidation password = new PasswordValidation(textboxPassword.Text);

                if (password.Validate(textboxID.Text))
                {
                    MessageBox.Show("Valid password.");
                    LoginFormInitializer.SetID(id.GetFullID());
                    LoginFormInitializer.SetIDType(id.GetIdType());
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Invalid password.");
                }
            }
            else
            {
                MessageBox.Show("Invalid ID.");
            }
        }
Ejemplo n.º 4
0
        public int GetValidPasswords(int start, int end)
        {
            var passwordValidation = new PasswordValidation(_structureValidation, _sequenceValidation);
            var count = 0;

            for (var i = start; i <= end; i++)
            {
                count += passwordValidation.Validate(i.ToString()) ? 1 : 0;
            }

            return(count);
        }
Ejemplo n.º 5
0
        private void LoginPasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
        {
            var(resourceValue, validate) = PasswordValidation.Validate(LoginPasswordBox.Password);

            if (DataContext != null)
            {
                ((AuthViewModel)DataContext).LoginValidate = resourceValue;
            }

            LoginValidateBlock.Visibility =
                LoginValidateBlock.Text == App.GetResourceValue("MbPasswordSuccess")
                                        ? Visibility.Collapsed
                                        : Visibility.Visible;

            (DataContext as AuthViewModel) !.IsLoginPasswordCorrect = validate;
        }
Ejemplo n.º 6
0
        private void ConfirmPasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
        {
            if (DataContext != null)
            {
                var(resourceValue, validate) = PasswordValidation.Validate(ConfirmPasswordBox.Password);

                ConfirmPasswordValidateBlock.Text = resourceValue;
                IsConfirmPasswordValid            = validate;
            }

            ConfirmPasswordValidateBlock.Visibility =
                ConfirmPasswordValidateBlock.Text == App.GetResourceValue("MbPasswordSuccess")
                                        ? Visibility.Collapsed
                                        : Visibility.Visible;

            PasswordValidate();
        }
Ejemplo n.º 7
0
        public void IncorrectPassword()
        {
            //Arrange
            BoardGameDatabase.Interfaces.Validators.IPasswordValidation validPassword = new PasswordValidation();

            string passwordNull            = "";
            string passwordTooShort        = "Sho1!";
            string passwordTooLong         = "123456789O!23456709";
            string passwordWhiteSpace      = "Some Pass1!";
            string passwordNoDigital       = "bezrZadnejCyfr!";
            string passwordNoUpperSymbol   = "samemałeli!1";
            string passwordNoSpecialSymbol = "SomePass1";

            string passwordWhiteSpaceNoSpecial = "Some Pass 1";
            string passwordVeryBad             = "s ho";

            //Act
            var resultNull            = validPassword.Validate(passwordNull);
            var resultTooShort        = validPassword.Validate(passwordTooShort);
            var resultTooLong         = validPassword.Validate(passwordTooLong);
            var resultWhiteSpace      = validPassword.Validate(passwordWhiteSpace);
            var resultNoDigital       = validPassword.Validate(passwordNoDigital);
            var resultNoUpperSymbol   = validPassword.Validate(passwordNoUpperSymbol);
            var resultNoSpecialSymbol = validPassword.Validate(passwordNoSpecialSymbol);

            var resultWhiteSpaceNoSpecial = validPassword.Validate(passwordWhiteSpaceNoSpecial);
            var resultVeryBad             = validPassword.Validate(passwordVeryBad);


            //Assert
            Assert.AreEqual(resultNull.IsSucces, false);
            Assert.AreEqual(resultNull.ErrorList.Keys.All(a => a == ValidationKey.NoPassword.ToString()), true);
            Assert.AreEqual(resultNull.ErrorList.Keys.Count, 1);

            Assert.AreEqual(resultTooShort.IsSucces, false);
            Assert.AreEqual(resultTooShort.ErrorList.Keys.All(a => a == ValidationKey.PasswordTooShort.ToString()), true);
            Assert.AreEqual(resultTooShort.ErrorList.Keys.Count, 1);

            Assert.AreEqual(resultTooLong.IsSucces, false);
            Assert.AreEqual(resultTooLong.ErrorList.Keys.All(a => a == ValidationKey.PasswordTooLong.ToString()), true);
            Assert.AreEqual(resultTooLong.ErrorList.Keys.Count, 1);

            Assert.AreEqual(resultWhiteSpace.IsSucces, false);
            Assert.AreEqual(resultWhiteSpace.ErrorList.Keys.All(a => a == ValidationKey.PasswordHaveWhiteSpace.ToString()), true);
            Assert.AreEqual(resultWhiteSpace.ErrorList.Keys.Count, 1);

            Assert.AreEqual(resultNoDigital.IsSucces, false);
            Assert.AreEqual(resultNoDigital.ErrorList.Keys.All(a => a == ValidationKey.PasswordNoDigit.ToString()), true);
            Assert.AreEqual(resultNoDigital.ErrorList.Keys.Count, 1);

            Assert.AreEqual(resultNoUpperSymbol.IsSucces, false);
            Assert.AreEqual(resultNoUpperSymbol.ErrorList.Keys.All(a => a == ValidationKey.PasswordNoUpperSymbol.ToString()), true);
            Assert.AreEqual(resultNoUpperSymbol.ErrorList.Keys.Count, 1);

            Assert.AreEqual(resultNoSpecialSymbol.IsSucces, false);
            Assert.AreEqual(resultNoSpecialSymbol.ErrorList.Keys.All(a => a == ValidationKey.PasswordNoSpecialSymbol.ToString()), true);
            Assert.AreEqual(resultNoSpecialSymbol.ErrorList.Keys.Count, 1);

            Assert.AreEqual(resultNoSpecialSymbol.IsSucces, false);
            Assert.AreEqual(resultNoSpecialSymbol.ErrorList.Keys.All(a => a == ValidationKey.PasswordNoSpecialSymbol.ToString()), true);
            Assert.AreEqual(resultNoSpecialSymbol.ErrorList.Keys.Count, 1);

            Assert.AreEqual(resultWhiteSpaceNoSpecial.IsSucces, false);
            Assert.AreEqual(resultWhiteSpaceNoSpecial.ErrorList.Keys.Any(a => a == ValidationKey.PasswordNoSpecialSymbol.ToString()), true);
            Assert.AreEqual(resultWhiteSpaceNoSpecial.ErrorList.Keys.Any(a => a == ValidationKey.PasswordHaveWhiteSpace.ToString()), true);
            Assert.AreEqual(resultWhiteSpaceNoSpecial.ErrorList.Keys.Count, 2);

            Assert.AreEqual(resultVeryBad.IsSucces, false);
            Assert.AreEqual(resultVeryBad.ErrorList.Keys.Any(a => a == ValidationKey.PasswordTooShort.ToString()), true);
            Assert.AreEqual(resultVeryBad.ErrorList.Keys.Any(a => a == ValidationKey.PasswordHaveWhiteSpace.ToString()), true);
            Assert.AreEqual(resultVeryBad.ErrorList.Keys.Any(a => a == ValidationKey.PasswordNoDigit.ToString()), true);
            Assert.AreEqual(resultVeryBad.ErrorList.Keys.Any(a => a == ValidationKey.PasswordNoSpecialSymbol.ToString()), true);
            Assert.AreEqual(resultVeryBad.ErrorList.Keys.Any(a => a == ValidationKey.PasswordNoUpperSymbol.ToString()), true);
            Assert.AreEqual(resultVeryBad.ErrorList.Keys.Count, 5);
        }