public void CheckPassword_Matches_ShouldReturnTrue() { //Arrange var checkPassword = new AuthControllerServices(); var hashPassword = new HashPassword(); var user = UserData().Where(u => u.Id == 1).SingleOrDefault(); var userViewmodel = UserViewModelData(); //Act var actual = checkPassword.CheckPassword(user, userViewmodel, hashPassword); //Assert Assert.True(actual); }
public IActionResult Login(UserViewmodel userViewModel) { var users = _userService.GetAll().ToArray(); bool emailExist = _authControllerServices.CheckMailAddress(users, userViewModel); if (emailExist == true) { var user = _userService.GetUserByLogin(userViewModel.Login); bool isValid = _authControllerServices.CheckPassword(user, userViewModel, _hashPassword); if (isValid == true) { var AuthUser = Mapper.ModelToViewModelMapping.UserViewmodel(user); var tokenString = _authControllerServices.CreateTokenToString(_configuration); AuthUser.Token = tokenString; return(Ok(AuthUser)); } } return(BadRequest("Användarnamnet eller lösenordet är felaktigt.")); }