コード例 #1
0
        public ActionResult Login(string user, string password)
        {
            string passEncrip = UsuarioController.HashSHA1(password);

            using (var db = new inventarioEntities1())
            {
                var userLogin = db.usuario.FirstOrDefault(e => e.email == user && e.password == passEncrip);
                if (userLogin != null)
                {
                    FormsAuthentication.SetAuthCookie(userLogin.email, true);
                    Session["User"] = userLogin;
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(Login("Verifique sus datos"));
                }
            }
        }
コード例 #2
0
        public ActionResult Create(usuario usuario)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                using (var db = new inventarioEntities1())
                {
                    usuario.password = UsuarioController.HashSHA1(usuario.password);
                    db.usuario.Add(usuario);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "error " + ex);
                return(View());
            }
        }