Example #1
0
        private void AddUser(object parameter)
        {
            UserValidation     userValidation     = new UserValidation(_userRepository);
            PasswordValidation passwordValidation = new PasswordValidation();

            try
            {
                userValidation.ValidateUserNameRegistration(UserName);
            }
            catch (ValidationException ex)
            {
                ErrorMessage = ex.Message;
                return;
            }

            try
            {
                passwordValidation.ValidatePasswordRegistration(Password, RepeatPassword);
            }
            catch (ValidationException ex)
            {
                ErrorMessage = ex.Message;
                return;
            }

            _userRepository.AddUser(new User()
            {
                Name = UserName, Password = passwordValidation.HashPassword(Password)
            });
            CurrentUser.Login(_userRepository.GetUserByName(UserName));
            CloseAction();
        }
        private void Login(object parameter)
        {
            ErrorMessage = null;
            User               user;
            UserValidation     userValidation     = new UserValidation(_userRepository);
            PasswordValidation passwordValidation = new PasswordValidation();

            try
            {
                userValidation.ValidateUserNameSignIn(UserName);
            }
            catch (ValidationException ex)
            {
                ErrorMessage = ex.Message;
                return;
            }

            user = _userRepository.GetUserByName(UserName);

            try
            {
                passwordValidation.ValidatePasswordSignIn(user.Password, Password);
            }
            catch (ValidationException ex)
            {
                ErrorMessage = ex.Message;
                return;
            }

            CurrentUser.Login(user);
            CloseAction();
        }
Example #3
0
        public void LockFile(string filepath, string password)
        {
            Validate PasswordValidate = new PasswordValidation(password);

            PasswordValidate.ValidateData();
            Validate FileExistsValidate = new SBNExists(Path.GetFileName(filepath));

            FileExistsValidate.ValidateData();
            CreateSTF GenerateSTF = new CreateSTF(filepath, HEADERCODE, ENDMARKER);

            GenerateSTF.GenerateSTF();

            IEncrypt Encrypter = new InstantiateElement().CreateNewInstance(ConfigurationSettings.AppSettings["Encrypter_Assembly"], Path.GetFileName(filepath), password) as IEncrypt;

            Encrypter.EncryptFile();
            string STFFilename = ConfigurationSettings.AppSettings["AllEntityLocation"] + Path.GetFileName(filepath) + "." + ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"];

            if (File.Exists(STFFilename))
            {
                File.Delete(STFFilename);
            }
            if (bool.Parse(ConfigurationSettings.AppSettings["DeleteSource"]) == true)
            {
                if (System.IO.File.Exists(filepath))
                {
                    System.IO.File.Delete(filepath);
                }
            }
        }
Example #4
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;
            }
        }
Example #5
0
 public static void SetInitial(PasswordValidation BloodBankSystem)  //this method should fire when starts
 {
     oldloc      = BloodBankSystem.Location;
     oldSize     = BloodBankSystem.Size;
     defaultloc  = BloodBankSystem.Location;
     defaultSize = BloodBankSystem.Size;
 }
Example #6
0
        public object UserValidatePasswordById(Guid userId, [FromBody] PasswordValidation data)
        {
            if (string.IsNullOrWhiteSpace(data.Password))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, @"No password provided."));
            }

            if (!Regex.IsMatch(data.Password.ToUpper().Trim(), "^[0-9A-Fa-f]{64}$", RegexOptions.Compiled))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, @"Did not receive a valid password."));
            }

            var user = Database.PlayerData.User.Find(userId);

            if (user == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $@"No user with name '{userId}'."));
            }

            if (user.IsPasswordValid(data.Password.ToUpper().Trim()))
            {
                return(Request.CreateMessageResponse(HttpStatusCode.OK, "Password Correct"));
            }

            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, @"Invalid credentials."));
        }
Example #7
0
 public static void DoFullScreen(PasswordValidation bloodbank)
 {
     if (isfull == false)   //app not fullscreen, then fullscreen it
     {
         oldloc  = new Point(bloodbank.Location.X, bloodbank.Location.Y);
         oldSize = new Size(bloodbank.Size.Width, bloodbank.Size.Height);
         FullScreen(bloodbank);
         ismax  = false;
         isfull = true;
     }
     else //app is currently fullscreen so make it normal
     {
         if (oldSize.Width >= SystemInformation.WorkingArea.Width || oldSize.Height >= SystemInformation.WorkingArea.Height)
         {
             bloodbank.Location = defaultloc;
             bloodbank.Size     = defaultSize;
         }
         else
         {
             bloodbank.Location = oldloc;
             bloodbank.Size     = oldSize;
         }
         FullScreen(bloodbank);
         ismax  = false;
         isfull = false;
     }
 }
Example #8
0
        public static void DoMaximize(PasswordValidation bloodbank)
        {
            if (ismax == false)   //app not maximize, then maximized it
            {
                oldloc  = new Point(bloodbank.Location.X, bloodbank.Location.Y);
                oldSize = new Size(bloodbank.Size.Width, bloodbank.Size.Height);
                Maximized(bloodbank);
                ismax  = true;
                isfull = false;
            }
            else //app is currently maximized so make it normal
            {
                if (oldSize.Width >= SystemInformation.WorkingArea.Width || oldSize.Height >= SystemInformation.WorkingArea.Height)
                {
                    bloodbank.Location = defaultloc;
                    bloodbank.Size     = defaultSize;
                }
                else
                {
                    bloodbank.Location = oldloc;
                    bloodbank.Size     = oldSize;
                }

                ismax  = false;
                isfull = false;
            }
        }
Example #9
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.");
            }
        }
Example #10
0
        public void ComparePassword()
        {
            //Arrange
            BoardGameDatabase.Interfaces.Validators.IPasswordValidation validation = new PasswordValidation();

            string password1 = "someG0)dPa$";
            string password2 = "Ano*9Pa@@s";

            //Act
            var resultOk1                = validation.ComparePassword(password1, BoardGameDatabase.Operations.HashEncryption.Hash(password1));
            var resultOk2                = validation.ComparePassword(password2, BoardGameDatabase.Operations.HashEncryption.Hash(password2));
            var resultNotCompare         = validation.ComparePassword(password1, BoardGameDatabase.Operations.HashEncryption.Hash(password2));
            var resultNullPassword       = validation.ComparePassword(null, BoardGameDatabase.Operations.HashEncryption.Hash(password1));
            var resultWitheSpacePassword = validation.ComparePassword(" ", BoardGameDatabase.Operations.HashEncryption.Hash(password1));


            //Assert
            Assert.AreEqual(resultOk1.IsSucces, true);
            Assert.AreEqual(resultOk1.ErrorList.Count, 0);

            Assert.AreEqual(resultOk2.IsSucces, true);
            Assert.AreEqual(resultOk2.ErrorList.Count, 0);

            Assert.AreEqual(resultNotCompare.IsSucces, false);
            Assert.AreEqual(resultNotCompare.ErrorList.Any(a => a.Key == ValidationKey.PasswordNotCompare.ToString()), true);
            Assert.AreEqual(resultNotCompare.ErrorList.Count, 1);

            Assert.AreEqual(resultNullPassword.IsSucces, false);
            Assert.AreEqual(resultNullPassword.ErrorList.Any(a => a.Key == ValidationKey.NoPassword.ToString()), true);
            Assert.AreEqual(resultNullPassword.ErrorList.Count, 1);

            Assert.AreEqual(resultWitheSpacePassword.IsSucces, false);
            Assert.AreEqual(resultWitheSpacePassword.ErrorList.Any(a => a.Key == ValidationKey.NoPassword.ToString()), true);
            Assert.AreEqual(resultWitheSpacePassword.ErrorList.Count, 1);
        }
        public void ValidatePasswordSignIn_PasswordIsNull_ExpectedException()
        {
            string             password       = null;
            string             hashedPassword = "******"; //Ff-117
            PasswordValidation passValidation = new PasswordValidation();

            passValidation.ValidatePasswordSignIn(hashedPassword, password);
        }
        public void ValidatePasswordRegistration_PasswordIsNull_ExpectedException()
        {
            string             password       = null;
            string             repeatPassword = null;
            PasswordValidation passValidation = new PasswordValidation();

            passValidation.ValidatePasswordRegistration(password, repeatPassword);
        }
        public void ValidatePasswordRegistration_InvalidPasswordLength_ExpectedException()
        {
            string             password       = "******";
            string             repeatPassword = "******";
            PasswordValidation passValidation = new PasswordValidation();

            passValidation.ValidatePasswordRegistration(password, repeatPassword);
        }
Example #14
0
        public LoginScreenViewModel(LoginScreen loginScreenOpen)
        {
            loginScreen = loginScreenOpen;

            passwordValidation = new PasswordValidation();
            user    = new tblUser();
            service = new Service();
        }
        public void IsValid_GivenPositionEqualityMode_ReturnsCorrectResult(char letter, int min, int max, string password, bool expectedResult)
        {
            var validation = new PasswordValidation(new PasswordRule(letter, min, max), password);

            var result = validation.IsValid(PasswordRuleMode.PositionEquality);

            Assert.AreEqual(expectedResult, result);
        }
Example #16
0
        public static void Maximized(PasswordValidation bloodbank)
        {
            int x = SystemInformation.WorkingArea.Width;
            int y = SystemInformation.WorkingArea.Height;

            bloodbank.WindowState = FormWindowState.Normal;
            bloodbank.Location    = new Point(0, 0);
            bloodbank.Size        = new Size(x, y);
        }
 private void SubmitCommandExecute(object obj)
 {
     try
     {
         string password = (obj as PasswordBox).Password;
         if (UserName.Equals("Admin") && password.Equals("Admin123"))
         {
             if (!users.IsUser("Admin"))
             {
                 User.Username       = UserName;
                 User.Password       = password;
                 User.NameAndSurname = "Administrator";
                 users.AddUser(User);
                 AdminView admin = new AdminView();
                 loginScreen.Close();
                 admin.ShowDialog();
             }
             else
             {
                 AdminView admin = new AdminView();
                 loginScreen.Close();
                 admin.ShowDialog();
             }
         }
         else if (users.IsUser(UserName))
         {
             User = users.FindUser(UserName);
             if (SecurePasswordHasher.Verify(password, User.Password))
             {
                 UserView userWindow = new UserView(User);
                 loginScreen.Close();
                 userWindow.ShowDialog();
             }
             else
             {
                 MessageBox.Show("Wrong password!");
             }
         }
         else
         {
             if (PasswordValidation.PasswordOk(password))
             {
                 NameAndSurnameView nameAndSurnameView = new NameAndSurnameView(UserName, password);
                 loginScreen.Close();
                 nameAndSurnameView.ShowDialog();
             }
             else
             {
                 MessageBox.Show("Password must contain at least 5 characters!");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Example #18
0
        public void ParseValidation_GivenValidInput_ReturnsParsedValidation(string input, char expectedChar, int expectedMin,
                                                                            int expectedMax, string expectedPassword)
        {
            var expectedResult =
                new PasswordValidation(new PasswordRule(expectedChar, expectedMin, expectedMax), expectedPassword);

            var result = InputParser.ParseValidation(input);

            Assert.AreEqual(expectedResult, result);
        }
Example #19
0
 static void FullScreen(PasswordValidation bloodbank)
 {
     if (bloodbank.WindowState == FormWindowState.Maximized)
     {
         bloodbank.WindowState = FormWindowState.Normal;
     }
     else if (bloodbank.WindowState == FormWindowState.Normal)
     {
         bloodbank.WindowState = FormWindowState.Maximized;
     }
 }
Example #20
0
 public static void Minimized(PasswordValidation bloodbank)
 {
     if (bloodbank.WindowState == FormWindowState.Minimized)
     {
         bloodbank.WindowState = FormWindowState.Normal;
     }
     else if (bloodbank.WindowState == FormWindowState.Normal)
     {
         bloodbank.WindowState = FormWindowState.Minimized;
     }
 }
Example #21
0
 public static void ValidatePassword(string pass)
 {
     if (PasswordValidation.ValidatePassword(pass) == false)
     {
         Console.WriteLine("Try to enter a STRONG password!");
         GetPassword();
     }
     else
     {
         DisplayPassword(pass);
     }
 }
Example #22
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);
        }
Example #23
0
        public void SenhaDeveSerNoMinimoAceitavel(string senha)
        {
            var password = new PasswordValidation(new PasswordSize(), new PasswordDigits(), new PasswordLowerCaseLetters(), new PasswordUpperCaseLetters(), new PasswordSpecialCharacters(), new PasswordRepeatedCharacters());

            var isValid = password.IsValid(senha);

            Assert.True(isValid, "A senha informada e invalida.");

            var forcaSenha = password.GetPasswordStrength();

            Assert.False((forcaSenha == PasswordStrength.Unacceptable || forcaSenha == PasswordStrength.Weak), $"A senha não é forte o suficiente.");
        }
Example #24
0
        public bool Check(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                if (PasswordValidation == null)
                {
                    return(false);
                }

                return(PasswordValidation.Equals(value));
            }
            else
            {
                return(false);
            }
        }
Example #25
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;
        }
Example #26
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);
        }
        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();
        }
Example #28
0
        public void UnlockFolder(string Filename, string NewRoot, string Password)
        {
            #region Unlock Folder Implementation
            Validate PasswordValidate = new PasswordValidation(Password);
            PasswordValidate.ValidateData();
            string   SBNFilename = GetSBNName(Filename);
            string   STFFilename = GetSTFName(Filename);
            IDecrypt Decrypter   = new InstantiateElement().CreateNewInstance(ConfigurationSettings.AppSettings["Decrypter_Assembly"], Path.GetFileName(SBNFilename), Password) as IDecrypt;
            try
            {
                Decrypter.DecryptFile();
            }
            catch (Exception DecryptException)
            {
                throw (new ApplicationException("Incorrect password"));
            }

            ExtractSTF         ExtractSTFFile = new ExtractSTF(STFFilename);
            UnlockParameters   STFContents    = ExtractSTFFile.ExtractSTFContents();
            VerifySTFIntegrity CheckIntegrity = new VerifySTFIntegrity();
            if (!CheckIntegrity.Verify(STFContents.FooterCode))
            {
                throw (new ApplicationException("Incorrect password"));
            }
            DirectoryStructure CreateNewDirStructure = new DirectoryStructure(NewRoot, STFContents.XmlHeirarchy);
            CreateNewDirStructure.CreateDirectoryStructure();
            RestoreFiles RestoreFilesFromSTF = new RestoreFiles(STFContents.XmlHeirarchy, STFContents.FileAttributes, NewRoot, STFFilename);
            RestoreFilesFromSTF.ExecuteRestore();
            if (System.IO.File.Exists(STFFilename))
            {
                System.IO.File.Delete(STFFilename);
            }
            if (System.IO.File.Exists(ConfigurationSettings.AppSettings["AllEntityLocation"] + SBNFilename))
            {
                System.IO.File.Delete(ConfigurationSettings.AppSettings["AllEntityLocation"] + SBNFilename);
            }
            if (System.IO.File.Exists("GeneratedHierarchy.xml"))
            {
                System.IO.File.Delete("GeneratedHierarchy.xml");
            }



            #endregion
        }
Example #29
0
        public async Task <bool> ValidateUser()
        {
            //if is valid:
            if (PasswordValidation.IsValid(user.Password))
            {
                ((CustomAuthenticationStateProvider)AuthenticationStateProvider).MarkUserAsAuthenticated(PasswordValidation.GetHash(user.Password));

                await sessionStorage.SetItemAsync("hash", PasswordValidation.GetHash(user.Password));

                NavigationManager.NavigateTo("/editing");
            }
            else
            {
                LoginMessage = "Access is denied! Try again";
            }

            return(await Task.Run(() => true));
        }
Example #30
0
        public void LockFolder(string absoluteFolderPath, string Password)
        {
            #region LockFolder implementation
            LockParameters.FlushAll();
            Validate PasswordValidate = new PasswordValidation(Password);
            PasswordValidate.ValidateData();
            string   DirectoryName        = GetLeafDirectoryName(absoluteFolderPath);
            Validate FolderExistsValidate = new SBNExists(Path.GetFileName(DirectoryName));
            FolderExistsValidate.ValidateData();
            CreateFolderHierarchy createFolderHierarchy = new CreateFolderHierarchy(absoluteFolderPath);
            Root   fileSystemHierarchyManager           = createFolderHierarchy.FolderHierarchy;
            string DirName = Path.GetFileName(absoluteFolderPath);
            ConfigurationManager SaveConfiguration = new ConfigurationManager();
            SaveConfiguration.WriteFileHierarchyXml("HierarchySize.xml", fileSystemHierarchyManager);
            System.IO.FileInfo finfo = new FileInfo("HierarchySize.xml");
            long SizeOfXmlBlock      = finfo.Length;
            try
            {
                CreateSTF STF = new CreateSTF(SECURITYCODE, SizeOfXmlBlock, DirName, ENDMARKER, fileSystemHierarchyManager);
            }
            catch (Exception ex)
            {
                throw (new ApplicationException(ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"] + " File Creation Failed"));
            }
            IEncrypt Encrypter = new InstantiateElement().CreateNewInstance(ConfigurationSettings.AppSettings["Encrypter_Assembly"], DirName, Password) as IEncrypt;
            Encrypter.EncryptFile();
            System.IO.File.Delete(ConfigurationSettings.AppSettings["AllEntityLocation"] + DirName + "." + ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"]);
            if (bool.Parse(ConfigurationSettings.AppSettings["DeleteSource"]) == true)
            {
                if (System.IO.Directory.Exists(absoluteFolderPath))
                {
                    System.IO.Directory.Delete(absoluteFolderPath, true);
                }
            }

            if (System.IO.File.Exists("HierarchySize.xml"))
            {
                System.IO.File.Delete("HierarchySize.xml");
            }



            #endregion
        }