private AccessTokenResponse AuthenticateByUsernameAndPassword(UserAuthentication userAuthen) { var user = repository.GetUserByUsername(userAuthen.Username); AccessTokenResponse token = null; UserAuthenticationValidation validation = new UserAuthenticationValidation(); var validationResult = validation.Validate(userAuthen); if (!validationResult.IsValid || user == null) { throw new BaseException(ErrorMessage.CREDENTIALS_NOT_MATCH); } var result = PasswordManipulation.VerifyPasswordHash(userAuthen.Password, user.PasswordHash, user.PasswordSalt); if (user != null && result) { token = CreateToken(user); } else { throw new BaseException(ErrorMessage.CREDENTIALS_NOT_MATCH); } return(token); }
public IActionResult GetAuthentication([FromBody] DTOUserCredentials body) { try { var validator = new UserAuthenticationValidation(); var rusultValidation = validator.Validate(body); if (!rusultValidation.IsValid) { return(BadRequest(rusultValidation.Errors)); } var resultAuthentication = _authService.Execute(body); if (resultAuthentication != null) { var dto = _mapper.Map <DTOResultAuthentication>(resultAuthentication); return(Ok(dto)); } return(BadRequest("Email ou senha invalido tente novamente.")); } catch { return(StatusCode((int)HttpStatusCode.InternalServerError, ErroMessage)); } }