public ActionResult Login(User model)// кастомная модель { if (ModelState.IsValid) { if (Membership.ValidateUser(model.Email, model.Password)) { FormsAuthentication.SetAuthCookie(model.Email, false); return RedirectToAction("List", "Student"); } else { ModelState.AddModelError("", "Ви ввели невірний пароль"); } } return View(model); }
public MembershipUser CreateUser(string email, string password) { MembershipUser membershipUser = GetUser(email, false); if (membershipUser == null) { try { using (StudentListContext _db = new StudentListContext()) { User user = new User(); user.Email = email; user.Password = Crypto.HashPassword(password); _db.Users.Add(user); _db.SaveChanges(); membershipUser = GetUser(email, false); return membershipUser; } } catch { return null; } } return null; }