Reputation: 1074
Trying to make a very simple form of authentication in asp.net5 but seems like they removed the form authentication. What else could I use to make a very simple authentication?
Thanks in advance
Upvotes: 2
Views: 4452
Reputation: 19608
You can do something like this.
if (authUser.Username == "admin" && authUser.Password == "admin")
{
var claims = new[] { new Claim("name", authUser.Username), new Claim(ClaimTypes.Role, "Admin") };
var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
Context.Authentication.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));
return Redirect("~/Home/Index");
}
Sample code - https://github.com/anuraj/CookieAuthMVCSample
Upvotes: 6