public ActionResult Login(User user)
        {
            if(user.Username == null || user.Password == null)
            {
                return View();
            }
            else if (!ModelState.IsValidField(user.Username))
            {
                ModelState.AddModelError("", "Username is invalid!");
                return View();
            }
            else if (!ModelState.IsValidField(user.Password))
            {
                ModelState.AddModelError("", "Password is invalid!");
            }
            else if(ModelState.IsValidField(user.Username) && ModelState.IsValidField(user.Password) && LoginCheck(user))
            {
                Session["Username"] = user.Username;
                return RedirectToAction(user.Username, "User");
            }
            else
            {
                return View();
            }

            return View();
        }
Example #2
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(user);
        }
Example #3
0
 public ActionResult Index(User model)
 {
     if (ModelState.IsValid)
     {
         if (IsUser(model.username, model.password)) //Check data store where username password exists
         {
             //Set false to true to make the cookie persistante between sessions
             FormsAuthentication.SetAuthCookie(model.username, false);
             return RedirectToAction("index", "home");
         }
         ModelState.AddModelError("", "Invalid username or password");
     }
     return View();
 }
 public bool LoginCheck(User u)
 {
     if(u.Username != null && u.Password != null)
     {
         var pass = Crypto.SHA256(u.Password);
         var v = db.Users.Where(a => a.Username.Equals(u.Username) && a.Password.Equals(pass)).FirstOrDefault();
         if (v != null)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     return false;
 }
Example #5
0
 public ActionResult Edit(User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(user);
 }