public ActionResult Login(string submit, LoginModel model)
        {
            USERS iUser = new USERS();
            DataTable dt = iUser.GetUserInfo(model);

            if (dt.Rows.Count > 0)
            {
                if ((model.UserName == dt.Rows[0]["UserName"].ToString())
                    && (model.Password == dt.Rows[0]["Password"].ToString()))
                {
                    //model.Id = dt.Rows[0]["UserName"].ToString();
                    model.UserName = dt.Rows[0]["UserName"].ToString();
                    model.Password = dt.Rows[0]["Password"].ToString();
                    SetLoginSessionData(model, false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {

                    ModelState.AddModelError("UserName", "invalid username or password.");
                }
            }
            else
            {

                ModelState.AddModelError("UserName", "invalid username or password.");
            }

            return View("Login", model);
        }
示例#2
0
        public DataTable GetUserInfo(LoginModel param)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbConnection connection = db.CreateConnection();

            string sql = "SELECT USERID, UserName, Password, UserType FROM Usersatten.dbo.USERLOGIN WHERE UserName='******' and Password='******' ";
            DbCommand dbCommand = db.GetSqlStringCommand(sql);

            dbCommand.Connection = connection;
            connection.Open();
            DataSet ds = db.ExecuteDataSet(dbCommand);
            //IDataReader ds = db.ExecuteReader(dbCommand);
            connection.Close();
            return ds.Tables[0];
        }
 protected void SetUserSessionData(LoginModel LoginM)
 {
     //CurrentUserName = LoginM.Id + " " + LoginM.Password;
     CurrentUserPassword = LoginM.Password;
     CurrentUserName = LoginM.UserName;
     LoginDatetime = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");
     CurrentUserId = LoginM.USERID;
 }
 protected void SetLoginSessionData(LoginModel LoginM, bool createPersistentCookie)
 {
     SetUserSessionData(LoginM);
     FormsAuthentication.SetAuthCookie("1", createPersistentCookie);
     Session.Timeout = 1;
 }
示例#5
0
        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)
 {
     ModelState.Clear();
     return View("Login", model);
 }