Esempio n. 1
0
        public void Should_return_true_when_password_and_salt_matches_given_password()
        {
            // Given
            var encryptor      = new PasswordEncryptor();
            var storedPassword = new Password("UCnYe3MXz11RqTwoLfFpb2k2OUjUtMq/LMcLmJgDB8Q=", "yooQLE9ntD/yjCxi8bN35w==");

            // When
            var arePasswordsTheSame = encryptor.ComparePasswords("MijnGeheim", storedPassword);

            // Then
            Assert.AreEqual(arePasswordsTheSame, true);
        }
Esempio n. 2
0
        public void Should_return_false_when_given_password_is_correct_but_stored_hash_is_corrupted()
        {
            // Given
            var encryptor      = new PasswordEncryptor();
            var storedPassword = new Password("UCnYe3MXz11RqTwoLfFpb2k2OUjUtMq/LMcLmJgDB8Q=", "youQLE9ntD/yjCxi8bN35w==");

            // When
            var arePasswordsTheSame = encryptor.ComparePasswords("MijnGeheim", storedPassword);

            // Then
            Assert.AreEqual(arePasswordsTheSame, false);
        }
Esempio n. 3
0
        public CommandResult <LoginEmployeeResult> Handle(LoginEmployeeCommand command)
        {
            var employee = _unitOfWork.Employees.All.FirstOrDefault(e => e.Email == command.Email);

            if (employee == null)
            {
                return(new CommandFailedResult <LoginEmployeeResult>($"Invalid login attempt with email {command.Email}"));
            }

            if (!_passwordEncryptor.ComparePasswords(command.Password, employee.Password))
            {
                return(new CommandFailedResult <LoginEmployeeResult>($"Invalid login attempt with email {command.Email}"));
            }

            return(new CommandSuccessResult <LoginEmployeeResult>(new LoginEmployeeResult
            {
                Id = employee.ID,
                Name = employee.Name,
                EmployeeGroupId = employee.EmployeeGroup.Id,
                EmployerId = employee.Employer.Id
            }));
        }