Beispiel #1
0
        public void WhenIWantToCheckIfPasswordIsInHistory_AndDatabaseIsAvailable_IfPasswordIsNotInHistory_ItShouldReturnFalse()
        {
            var passwordHistoryList = new List <PasswordHistory>();

            passwordHistoryList.Add(new PasswordHistory {
                UserId = "2w3", PasswordHash = DocProcessingEncryption.Encrypt("gogo")
            });
            passwordHistoryList.Add(new PasswordHistory {
                UserId = "2w3", PasswordHash = DocProcessingEncryption.Encrypt("gogi")
            });
            passwordHistoryList.Add(new PasswordHistory {
                UserId = "2w3", PasswordHash = DocProcessingEncryption.Encrypt("gaga")
            });
            passwordHistoryList.Add(new PasswordHistory {
                UserId = "2w3", PasswordHash = DocProcessingEncryption.Encrypt("gigi")
            });

            this.passwordHistoryRepository.Setup(x => x.GetPasswordHistoryByLastItems(It.IsAny <String>(), It.IsAny <Int32>()))
            .Returns(passwordHistoryList);

            var result = this.passwordHistoryService.IsPasswordInHistory("2w3", "gugi");

            result.Should().BeFalse();
            this.passwordHistoryRepository.Verify(x => x.GetPasswordHistoryByLastItems(It.IsAny <String>(), It.IsAny <Int32>()), Times.AtLeastOnce);
        }
Beispiel #2
0
        private void StorePasswordInHistory(String userId, String password)
        {
            password = DocProcessingEncryption.Encrypt(password);

            this.passwordHistoryRepository.Create(
                new PasswordHistory
            {
                PasswordHash = password,
                UserId       = userId,
                LogDate      = DateTime.Now
            });
        }
Beispiel #3
0
        public Boolean IsPasswordInHistory(String userId, String passwordHash)
        {
            try
            {
                var passwordHistory = this.GetPasswordHistoryByLastItems(userId, 12);

                var passwordList = this.GetEncryptedPasswordList(passwordHistory);

                if (passwordList.Contains(DocProcessingEncryption.Encrypt(passwordHash)))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw new DocProcessingException("Unable to validate password in password history", e);
            }
        }