public IHttpActionResult Authenticate(LoginRequest login) { if (login == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } string json; string path = AppDomain.CurrentDomain.BaseDirectory + "UsuarioValido.json"; var User = new Models.LoginRequest(); using (StreamReader jsonStream = File.OpenText(path)) { json = jsonStream.ReadToEnd(); } User = JsonConvert.DeserializeObject <Models.LoginRequest>(json); bool isCredentialValid = (login.Password == User.Password.ToString() && login.Username == User.Username.ToString()); if (isCredentialValid) { var token = TokenGenerator.GenerateTokenJwt(login.Username); return(Ok(token)); } else { return(Unauthorized()); } }
public IHttpActionResult Authenticate(LoginRequest login) { if (login == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } //TODO: Validate credentials Correctly, this code is only for demo !! bool isCredentialValid = (login.Password == "123456"); if (isCredentialValid) { var token = TokenGenerator.GenerateTokenJwt(login.Username); return(Ok(token)); } else { return(Unauthorized()); } }