Exemplo n.º 1
0
 public SecurityAnswer(string answer, string securityQuestionId, string userId)
 {
     this.Id                 = Guid.NewGuid().ToString();
     this.Answer             = UnityEncryption.Encrypt(answer);
     this.SecurityQuestionId = securityQuestionId;
     this.UserId             = userId;
 }
Exemplo n.º 2
0
        public void WhenIWantToCheckIfPasswordIsInHistory_AndDatabaseIsAvailable_IfPasswordIsNotInHistory_ItShouldReturnFalse()
        {
            var passwordHistoryList = new List <PasswordHistory>();

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

            this._passwordHistoryRepository.Setup(x => x.GetPasswordHistoryByMonths(It.IsAny <string>(), It.IsAny <int>()))
            .Returns(passwordHistoryList);

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

            result.Should().BeFalse();
            this._passwordHistoryRepository.Verify(x => x.GetPasswordHistoryByMonths(It.IsAny <string>(), It.IsAny <int>()), Times.AtLeastOnce);
        }
Exemplo n.º 3
0
        private IList <string> GetDecryptedPasswordList(IList <PasswordHistory> passwordHistory, string passPhrase)
        {
            var passwordList = new List <string>();

            passwordHistory.ToList().ForEach(x => passwordList.Add(UnityEncryption.Decrypt(x.PasswordHash, passPhrase)));

            return(passwordList);
        }
Exemplo n.º 4
0
        private void StorePasswordInHistory(String userId, String password)
        {
            password = UnityEncryption.Encrypt(password);

            this._passwordHistoryRepository.Create(
                new PasswordHistory {
                PasswordHash = password, UserId = userId, LogDate = DateTime.Now
            });
        }
Exemplo n.º 5
0
        public bool SecurityAnswerIsValid(string userId, string securityQuestionId, string answer)
        {
            try
            {
                var securityAnswer = this.GetSecurityAnswer(userId, securityQuestionId);

                if (securityAnswer.Answer == UnityEncryption.Encrypt(answer))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw new UnityException("Unable to validate security answer", e);
            }
        }
Exemplo n.º 6
0
        public bool IsPasswordInHistory(string userId, string passwordHash)
        {
            try
            {
                var passwordHistory = this.GetPasswordHistoryByMonths(userId, 12);

                var passwordList = this.GetEncryptedPasswordList(passwordHistory);

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