private ClaimsIdentity GetIdentity(string username, string password) { var hasher = new CustomPasswordHasher(1000); var identity = _databaseContext.Identities.FirstOrDefault(x => x.Email == username); if (identity != null && hasher.Check(identity.Password, password).Verified) { var claims = new List <Claim> { new Claim(ClaimsIdentity.DefaultNameClaimType, identity.Id.ToString()), new Claim(ClaimsIdentity.DefaultRoleClaimType, identity.Role.GetString()) }; ClaimsIdentity claimsIdentity = new ClaimsIdentity(claims, "Token", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); return(claimsIdentity); } return(null); }