public ActionResult ChangePassword(ChangePasswordModel model) { if (ModelState.IsValid) { if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword)) { foodAppEntities db = new foodAppEntities(); try { var handle = db.User_acc.Single(n => n.name == User.Identity.Name && n.password == model.OldPassword); handle.password = model.NewPassword; db.SaveChanges(); } catch { ModelState.AddModelError("", "There was a problem finding the account."); } return RedirectToAction("ChangePasswordSuccess"); } else { ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); } } // If we got this far, something failed, redisplay form ViewData["PasswordLength"] = MembershipService.MinPasswordLength; return View(model); }
public bool ValidateUser(string userName, string password) { if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName"); if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password"); var db = new foodAppEntities(); List<User_acc> user = db.User_acc.Where(n => n.name == userName && n.password == password).Select(n => n).ToList(); if (user.Count != 1) { db.Dispose(); return false; } else { db.Dispose(); return true; } }
public bool changePass(string name,string oldPass,string newPass) { foodAppEntities db = new foodAppEntities(); List<User_acc> user = db.User_acc.Where(n => n.name == name && n.password == oldPass) .Select(n => n).ToList(); if (user.Count != 1) throw new ArgumentException("too many or two few entries with that username", "name"); user.FirstOrDefault().password = newPass; db.SaveChanges(); db.Dispose(); return true; }
public MembershipCreateStatus makeUser(string name, string password, int? number) { MembershipCreateStatus myStatus = MembershipCreateStatus.Success; foodAppEntities db = new foodAppEntities(); User_acc myacc = new User_acc(); List<User_acc> mylist = db.User_acc .Where(n=>(n.number == number)&&(String.IsNullOrEmpty(n.name)||(n.name == name))) .Select(n=>n).ToList(); if( mylist.Count > 0) return MembershipCreateStatus.DuplicateUserName; myacc.number = number.Value; myacc.name = name; myacc.password = password; db.AddToUser_acc(myacc); db.SaveChanges(); db.Dispose(); return myStatus; }