public IActionResult LoginTwoFactor(LoginTwoFactorVM model) { if (!ModelState.IsValid) { return(RedirectToAction("Login")); } Korisnik korisnik = ctx.Korisnik .SingleOrDefault(x => x.KorisnickoIme == model.username && x.LozinkaHash == PasswordSettings.GetHash(model.password, Convert.FromBase64String(x.LozinkaSalt))); if (korisnik == null) { ViewData["poruka"] = "Pogrešan username ili password"; return(View("Login")); } TwoFactorAuthenticator TwoFacAuth = new TwoFactorAuthenticator(); string current = TwoFacAuth.GetCurrentPIN(korisnik.TwoFactorUniqueKey); bool isValid = current.Equals(model.TwoFactorPin); //bool isValid = true; if (isValid) { HttpContext.SetLogiraniKorisnik(korisnik, snimiUCookie: model.ZapamtiLozinku); return(RedirectToAction("Index", "Home")); } else { ViewData["poruka"] = "Pogrešan kod"; return(View("LoginTwoFactor", model)); } }
public IActionResult Login(LoginVM input) { if (!ModelState.IsValid) { ViewData["poruka"] = "Niste unijeli ispravne podatke"; return(View("Index", input)); } Korisnik korisnik = ctx.Korisnik .SingleOrDefault(x => x.KorisnickoIme == input.username && x.LozinkaHash == PasswordSettings.GetHash(input.password, Convert.FromBase64String(x.LozinkaSalt))); if (korisnik == null) { ViewData["poruka"] = "Pogrešan username ili password"; return(View("Index", input)); } if (!String.IsNullOrEmpty(korisnik.TwoFactorUniqueKey)) { var twoFactorModel = new LoginTwoFactorVM { username = korisnik.KorisnickoIme, password = input.password, ZapamtiLozinku = input.ZapamtiPassword }; return(View("LoginTwoFactor", twoFactorModel)); } else { HttpContext.SetLogiraniKorisnik(korisnik, snimiUCookie: input.ZapamtiPassword); return(RedirectToAction("Index", "Home")); } }