public ActionResult <String> Login(User user) { User found = _userService.GetByEmail(user.Email); if (found != null && found.Password == user.Password) { var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var stringChars = new char[8]; var random = new Random(); for (int i = 0; i < stringChars.Length; i++) { stringChars[i] = chars[random.Next(chars.Length)]; } var token = new String(stringChars); _tokenService.AddTokenToArray(found.Id, token); found.MyToken = token; _userService.Update(found.Id, found); String responseToken = "{\"token\" :" + "\"" + token + "\"}"; return(responseToken); } String responseTokenError = "{\"message\" :" + "\"" + "Unauthorized!" + "\"}"; return(responseTokenError); }