Alternate login to ASP.Net MVC for authentication

After reading the tutorials and testing, I found the login with Identity in a confusing, inflexible way. Changing the username and completely deleting email was a nightmare (and I failed). It was my experience, and I had no strength left to continue the path of Owin Identity.

Are there alternatives to login to OWIN / Identity that are acceptable to the ASP.Net community as valid as OWIN / Identity? I have a project that needs minimalism (username, password, full name ONLY). I hope my question is not open and is within SO;)

+7
c # asp.net-mvc asp.net-identity owin
source share
1 answer

here's a simple owin auth implementation if you still want to try: (its code is copied from prodinner )

you need a class to configure it:

public static class OwinConfig { public static void ConfigureAuth(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/SignIn") }); } } 

The startup class in which the ConfigureAuth command is run

 [assembly: OwinStartup(typeof(Startup))] namespace Omu.ProDinner.WebUI { public class Startup { public void Configuration(IAppBuilder app) { OwinConfig.ConfigureAuth(app); } } } 

and AccountController where you use it:

 public class AccountController : Controller { //... ctor, user service private IAuthenticationManager Authentication { get { return HttpContext.GetOwinContext().Authentication; } } private void SignInOwin(string name, bool rememberMe, IEnumerable<string> roles) { var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, name) }, DefaultAuthenticationTypes.ApplicationCookie, ClaimTypes.Name, ClaimTypes.Role); foreach (var role in roles) { identity.AddClaim(new Claim(ClaimTypes.Role, role)); } Authentication.SignIn(new AuthenticationProperties { IsPersistent = rememberMe }, identity); } public ActionResult SignIn() { return View(); } [HttpPost] public ActionResult SignIn(SignInInput input) { if (!ModelState.IsValid) { input.Password = null; input.Login = null; return View(input); } var user = userService.Get(input.Login, input.Password); if (user == null) { ModelState.AddModelError("", "incorrect username or password"); return View(); } SignInOwin(user.Login, input.Remember, user.Roles.Select(o => o.Name)); return RedirectToAction("index", "home"); } public ActionResult SignOff() { Authentication.SignOut(); return RedirectToAction("SignIn", "Account"); } } 

and here is the list of packages you need:

  <package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net45" /> <package id="Microsoft.AspNet.Identity.Owin" version="2.2.1" targetFramework="net45" /> <package id="Microsoft.Owin" version="3.0.1" targetFramework="net45" /> <package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net45" /> <package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Cookies" version="3.0.1" targetFramework="net45" /> <package id="Microsoft.Owin.Security.OAuth" version="3.0.1" targetFramework="net45" /> <package id="Owin" version="1.0" targetFramework="net45" /> 
+6
source share

All Articles