private async void Login(LoginServiceResult loginModel) { var claims = new List <Claim> { new Claim(ClaimTypes.Name, loginModel.Login), new Claim(ClaimTypes.Role, loginModel.UserType.ToString()), new Claim(ClaimTypes.NameIdentifier, loginModel.ActualID.ToString()) }; ClaimsIdentity claimsIdentity = new ClaimsIdentity(claims, "ChatFurieLogin"); ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(claimsIdentity); await HttpContext.SignInAsync(claimsPrincipal); }
private LoginServiceResult GetLoginResult(LoginServiceContract contract, User user) { var loginReturn = new LoginServiceResult(); if (user != null && MD5Hash(contract?.Password).Equals(user.Password)) { loginReturn.UserId = user.Id; loginReturn.UserName = user.Login; loginReturn.Success = true; } else { loginReturn.Success = false; loginReturn.Error = "Неверное имя пользователя или пароль"; } return(loginReturn); }