public ActionResult Login(Models.LoginViewModel UserLogin) { User MyUser = (from U in db.Users where U.UserName == UserLogin.User.UserName select U).FirstOrDefault(); if (MyUser != null) { string MyPassword = Mycrypt.HashPassword(UserLogin.User.UserPassword, MyUser.UserSalt); User MyLogIn = (from U in db.Users where U.UserName == UserLogin.User.UserName && U.UserPassword == MyPassword select U).FirstOrDefault(); if (MyLogIn != null) { Session["User"] = UserLogin.User.UserName; return(RedirectToAction("Index", "Admin")); } else { UserLogin.Errmsg = "Wrong username or password!"; return(View(UserLogin)); } } UserLogin.Errmsg = "Wrong username or password!"; return(View(UserLogin)); }
public ActionResult Edit([Bind(Include = "Id,UserName,Password,Salt,Fk_Role")] UserTb userTb) { if (ModelState.IsValid) { string MySalt = Mycrypt.GetRandomSalt(); userTb.Salt = MySalt; userTb.Password = Mycrypt.HashPassword(userTb.Password, MySalt); db.Entry(userTb).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Fk_Role = new SelectList(db.RoleTbs, "Id", "Role", userTb.Fk_Role); return(View(userTb)); }
public ActionResult Index(UserTb Myuser) { UserTb TjekUser = db.UserTbs.Where(u => u.UserName == Myuser.UserName).FirstOrDefault(); if (TjekUser != null) { string PassWord = Mycrypt.HashPassword(Myuser.Password, TjekUser.Salt); UserTb NewUser = db.UserTbs.Where(u => u.UserName == TjekUser.UserName && u.Password == PassWord).FirstOrDefault(); if (NewUser != null) { Session["UserId"] = NewUser.Id; Session["UserName"] = NewUser.UserName; Session["UserPassword"] = NewUser.Password; Session["UserRole"] = NewUser.Fk_Role; Response.Redirect("~/EventsTbs"); } } return(View()); }