private void btnLogin_Click(object sender, EventArgs e) { string UserID = txtUserID.Text.Trim(); string Password = txtPassword.Text; if (string.IsNullOrEmpty(UserID)) { MessageBox.Show("Please input Username!"); return; } if (string.IsNullOrEmpty(Password)) { MessageBox.Show("Please input Password!"); return; } AccountDTO account = accountDAO.CheckLogin(UserID, Password); if (account != null) { frmHome frmHome = new frmHome(account); frmHome.Show(); this.Hide(); } else { MessageBox.Show("Username or Password is incorrect!"); } }
public ActionResult <IEnumerable <string> > PostAuthenUser([FromBody] AccountDTO account) { string token = AccountDAO.CheckLogin(context, account.Username, account.Password); if (token == null) { return(new JsonResult(rm.Error("Invalid username or password"))); } return(new JsonResult(rm.Success("Login successful", token))); }
public ActionResult Login(string username, string password) { if (username.Length > 0 && password.Length > 0) { AccountDAO accDao = new AccountDAO(); string role = accDao.CheckLogin(username, password); if (role.Length > 0) { if (Session["username"] == null) { Session.Add("username", username); Session.Add("role", role); } } } return(PartialView()); }
public JsonResult CheckLogin(string username, string password) { try { var rs = AccountDAO.CheckLogin(username, password); if (rs != null) { Session["User"] = rs; return(Json("Success", JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } return(Json("Fail", JsonRequestBehavior.AllowGet)); }
public JsonResult CheckLogin(string username, string password, bool remember) { try { var rs = AccountDAO.CheckLogin(username, password); if (rs) { Account acc = AccountDAO.GetAccountByUsername(username); Session["User"] = acc; if (remember) { CustomSerializeModel userModel = new CustomSerializeModel() { UserId = acc.ID, FullName = acc.Fullname, Email = acc.Email, }; string userData = JsonConvert.SerializeObject(userModel); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddDays(1), remember, userData); string encTicket = FormsAuthentication.Encrypt(ticket); HttpCookie faCookie = new HttpCookie("login_form_cre", encTicket) { Expires = ticket.Expiration }; Response.Cookies.Add(faCookie); } return(Json("Success")); } } catch (Exception ex) { return(Json("Fail")); } return(Json("Fail")); }
public ActionResult checkLogin(FormCollection col) { bool isValid = true; string username = col["username"]; string password = col["password"]; if (username == null || username.Equals("")) { isValid = false; ViewBag.UERR = "Please input Username!"; } if (username == null || username.Equals("")) { isValid = false; ViewBag.PERR = "Please input Password!"; } if (isValid) { Account acc = dao.CheckLogin(username, password); if (acc != null) { Session["Account"] = acc; return(RedirectToAction("LoadList", "Phone")); } else { ViewBag.Error = "Invalid Username / Password"; return(Index()); } } else { ViewBag.USERNAME = username; return(Index()); } }