Exemple #1
0
        public bool IsValidUser(UserDTO user)
        {
            var users        = GetUserList();
            var password     = HashUtil.Create(user.Password, _salt);
            var existingUser = users.FirstOrDefault(x => x.UserName == user.UserName && x.Password == password);

            return(existingUser != null);
        }
        public void HashMatchesText()
        {
            // Arrange
            var message = "passw0rd";
            var salt    = SaltUtil.Create();
            var hash    = HashUtil.Create(message, salt);

            // Act
            var match = HashUtil.Validate(message, salt, hash);

            // Assert
            Assert.True(match);
        }
        public void Hash_of_two_different_messages_dont_match()
        {
            // Arrange
            var message1 = "passw0rd";
            var message2 = "password";
            var salt     = SaltUtil.Create();

            // Act
            var hash1 = HashUtil.Create(message1, salt);
            var hash2 = HashUtil.Create(message2, salt);

            // Assert
            Assert.AreNotEqual(hash1, hash2);
        }
Exemple #4
0
        public User SaveUser(UserDTO userDto)
        {
            // add AutoMapper
            var user = new User
            {
                Password = HashUtil.Create(userDto.Password, _salt),
                UserId   = userDto.UserId,
                UserName = userDto.UserName
            };

            var response = _connectionService.Post("users", user);

            return(response.IsSuccessful ? user : null);
        }