public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { try { connection.Open(); MySqlCommand cmd = connection.CreateCommand(); cmd.CommandText = "Select * from users where username='******' And password='******' AND (active = 1 OR active is null)"; MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { //FormsAuthentication.SignOut(); FormsAuthentication.SetAuthCookie(string.Format("{0},{1},{2}", dr.GetInt32(0), model.UserName, dr.GetInt32(9)), model.RememberMe); RemoveCookie("TntqTrackit", Request, Response); if (model.RememberMe) { var cookie = new HttpCookie("TntqTrackit", EncryptionManager.EncryptRijndael(string.Format("{0},{1},{2}", dr.GetInt32(0), model.UserName, dr.GetInt32(9)))) { }; cookie.Expires = DateTime.Now.AddMonths(6); Response.Cookies.Add(cookie); } Session["ShowVouchers"] = dr.GetBoolean(13); var usertype = dr.GetInt32(9); if (usertype == 4) { return(RedirectToAction("Reports", "Booking")); } if (usertype == 5) { return(RedirectToAction("Index", "Voucher")); } if (string.IsNullOrEmpty(returnUrl)) { return(RedirectToAction("AddBookingB", "Booking")); } RedirectToLocal(returnUrl); } ModelState.AddModelError("", "The user name or password provided is incorrect."); } catch (Exception e) { } finally { if (connection.State == System.Data.ConnectionState.Open) { connection.Close(); } } } return(View(model)); }
private string CreateVerifcationToken(string email) { string key = "J962006#n4302009"; string sevenDaysFromNow = DateTime.Now.AddDays(7).ToShortDateString(); string value = email + "|" + sevenDaysFromNow; return(EncryptionManager.EncryptRijndael(value, key)); }