public async Task <IActionResult> Index(LoginViewModels model) { if (ModelState.IsValid) { var loginModelInputData = new LoginInputDataModel { Email = model.Input.Email, Password = _hash.EncryptString(model.Input.Password) }; var login = await _loginServices.CheckCredencial(loginModelInputData); if (!login.Status) { model.ErrorMessage = login.Error; return(View(model)); } if (!login.APIResponse) { model.ErrorMessage = "Incorrect credentials"; return(View(model)); } var claims = new List <Claim> { new Claim(ClaimTypes.Email, model.Input.Email) }; var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var authProperties = new AuthenticationProperties(); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties); return(RedirectToAction("Create", "Messages")); } model.ErrorMessage = "Wrong Data"; return(View(model)); }