public ActionResult LogOn(Users model, string returnUrl) { if (ModelState.IsValid) { if (Account.Instance.ValidateUser(model)) { FormsAuthentication.SetAuthCookie(model.Name, true); SimpleSessionPersister.Username = model.Name; if (model.Name.Equals(Constants.Administrator)) { SimpleSessionPersister.Roles = new string[] { Constants.RoleAdmin };//Constants.RoleAdmin, Constants.RoleUser return RedirectToAction("Admin", "Home", new { name = model.Name }); } else { SimpleSessionPersister.Roles = new string[] { Constants.RoleUser }; return RedirectToAction("User", "Home", new { name = model.Name }); } } else { ModelState.AddModelError("", "failed,please check your account and password!"); } } return View(model); }
public ActionResult Create(string nameTxt) { if (!ModelState.IsValid) return View(); try { // TODO: Add insert logic here // Added by Jane to hash user password //string username = col["nameTxt"]; string psw = "welcome"; string newPsw = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(psw, "MD5"); Users user = new Users(); user.Name = nameTxt; user.Password = newPsw; user.CreateDate = DateTime.Now; //user.Password = newPsw; //user.CreateDate = DateTime.Now; // end _entities.AddToUsers(user); _entities.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }
public bool CreateUser(Users model) { using (CMSEntities db = new CMSEntities()) { if (model != null) { Users aa = new Users(); aa.Password = model.Password; aa.Name = model.Name; db.AddToUsers(aa); db.SaveChanges(); return true; } } return false; }
public ActionResult AddUser(string name, string password) { if (string.IsNullOrEmpty(name)) { return null; } Users user = new Users() { Name = name, Password = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5") }; var db = new CMSEntities(); db.Users.AddObject(user); db.SaveChanges(); return PartialView("_UserList", this.GetAllUser()); }
public bool ValidateUser(Users model) { using (CMSEntities db = new CMSEntities()) { Users result = db.Users.FirstOrDefault(m => m.Name == model.Name); if (result != null) { string newPsw = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(model.Password, "MD5"); if (result.Password == newPsw) { return true; } else { return false; } } else { return false; } } }
/// <summary> /// Create a new Users object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="password">Initial value of the Password property.</param> /// <param name="createDate">Initial value of the CreateDate property.</param> public static Users CreateUsers(global::System.Int32 id, global::System.String name, global::System.String password, global::System.DateTime createDate) { Users users = new Users(); users.Id = id; users.Name = name; users.Password = password; users.CreateDate = createDate; return users; }
/// <summary> /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToUsers(Users users) { base.AddObject("Users", users); }
public ActionResult Reset(Users user) { return View(); }