public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
               {
                    if (Membership.ValidateUser(model.UserName, model.Password))
                    {
                         FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                         if (Url.IsLocalUrl(returnUrl))
                         {
                              return Redirect(returnUrl);
                         }
                         else
                         {
                              return RedirectToAction("Index", "Home");
                         }
                    }
                    else
                    {
                         ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
               }

               // If we got this far, something failed, redisplay form
               return View(model);
        }
        public ActionResult Login(LoginModel model, string returnUrl) {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) {
                return RedirectToLocal(returnUrl);
            }

            // ここで問題が発生した場合はフォームを再表示します
            ModelState.AddModelError("", "指定されたユーザー名またはパスワードが正しくありません。");
            return View(model);
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.UserName == "yanwen" & model.Password == "123456")
                    Response.Write("正确");
                else
                {
                    Response.Write("错误");
                }

            }
            return View();
        }
        public JsonResult JsonLogin(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid) {
                if (Membership.ValidateUser(model.UserName, model.Password)) {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    return Json(new { success = true, redirect = returnUrl });
                }
                else {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed
            return Json(new { errors = GetErrorsFromModelState() });
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var validUser = new SecurityContext().ValidateUser(model.UserName, model.Password);
                if (validUser)
                {
                    CreateAuthCookie(model.UserName);

                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }

                    return RedirectToAction("Index", "Home");
                }
            }

            return View(model);
        }
Exemple #7
0
 public ActionResult Index(LoginModel model)
 {
     if (ModelState.IsValid)
     {
             if(uzivService.VerifyUzivatel(model.Username, model.Password))
             {
                 FormsAuthentication.SetAuthCookie(model.Username, false);
                 return RedirectToAction("index", "home");
             }
              //using (DatabaseContext ctx = new DatabaseContext())
              //{
              //    if (ctx.IsUserValid(model.Username, model.Password))
              //    {
              //        FormsAuthentication.SetAuthCookie(model.Username, false);
              //        return RedirectToAction("index", "home");
              //    }
              //}
         ModelState.AddModelError("", "Neplatné uživatelské jméno/heslo!");
     }
     return View();
 }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            foreach (var item in db.Usuarios)
                {
                    string password = EncodePassword(model.Password);
                    if ((item.User == model.UserName) && (item.Password == password))
                    {
                        return Redirect("/Home/Index");
                    }
                    return RedirectToLocal(returnUrl);

            }

            // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
            ModelState.AddModelError("", "El nombre de usuario o la contraseña especificados son incorrectos.");
            return View(model);
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
              {
            return RedirectToLocal(returnUrl);
              }

              // Si nous sommes arrivés là, quelque chose a échoué, réafficher le formulaire
              ModelState.AddModelError("", "Le nom d'utilisateur ou mot de passe fourni est incorrect.");
              return View(model);
        }
Exemple #10
0
        public JsonResult JsonLogin(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    return Json(new { success = true, redirect = returnUrl });
                }
                else
                {
                    ModelState.AddModelError("", "指定されたユーザー名またはパスワードが正しくありません。");
                }
            }

            // ここまで移動した場合は、何らかのエラーが発生しています
            return Json(new { errors = GetErrorsFromModelState() });
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) {
                return RedirectToLocal(returnUrl);
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            ModelState.AddModelError("", "提供的用户名或密码不正确。");
            return View(model);
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // 如果執行到這裡,發生某項失敗,則重新顯示表單
            ModelState.AddModelError("", "所提供的使用者名稱或密碼不正確。");
            return View(model);
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // Se chegarmos até aqui e houver alguma falha, exibir novamente o formulário
            ModelState.AddModelError("", "O nome de usuário ou a senha fornecido está incorreto.");
            return View(model);
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // 이 경우 오류가 발생한 것이므로 폼을 다시 표시하십시오.
            ModelState.AddModelError("", "제공한 사용자 이름 또는 암호가 잘못되었습니다.");
            return View(model);
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
            ModelState.AddModelError("", "El nombre de usuario o la contraseña especificados son incorrectos.");
            return View(model);
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            ModelState.AddModelError("", "Имя пользователя или пароль указаны неверно.");
            return View(model);
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            //if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            //{
            //    return RedirectToLocal(returnUrl);
            //}
            AccountDAL dal = new AccountDAL();

            if (dal.IsAuthenticated(model.UserName, SecurityUtil.GetMD5Password(model.Password)))
            {
                FormsAuthentication.SetAuthCookie(model.UserName, true);
            }
            else
            {
                // 如果我们进行到这一步时某个地方出错,则重新显示表单
                ModelState.AddModelError("", "提供的用户名或密码不正确。");
            }

            return View(model);
        }