public ActionResult ResetPassword(ResetPassModel model) { if (ModelState.IsValid) { var Pass = (ResetPasswordRequest)Session["passReset"]; var Person = db.Registered_Person.Where(p => p.Person_ID == Pass.Person_ID).FirstOrDefault(); var deletePass = db.ResetPasswordRequests.Where(p => p.Person_ID == Person.Person_ID).FirstOrDefault(); var hashedPass = FormsAuthentication.HashPasswordForStoringInConfigFile(model.Person_Password, "MD5"); Person.Person_Password = hashedPass; db.Entry(Person).State = System.Data.Entity.EntityState.Modified; db.ResetPasswordRequests.Remove(deletePass); //create entry in action log global.addAudit("Students", "Student: Reset Password", "Update", Pass.Person_ID); db.SaveChanges(); TempData["Message"] = "Your password has been reset!"; TempData["classStyle"] = "success"; return(RedirectToAction("Login")); } else { return(View()); } }
public ActionResult ResetPassword(ResetPassModel mod) { using (TimchurDatabaseEntities ent = new TimchurDatabaseEntities()) { bool valid = ent.Users.Where(x => x.IDCardNumber == mod.Id && x.Email == mod.Email).Count() > 0; bool exist = false; foreach (String s in LoginController.email_key.Keys) { if (s.CompareTo(mod.Email) == 0) { exist = true; } } bool key_email_validation = exist && LoginController.email_key[mod.Email].CompareTo(mod.Key) == 0; if (valid && key_email_validation) { Cache.gen_lock.WaitOne(); var my_use = ent.Users.Where(x => x.IDCardNumber == mod.Id && x.Email == mod.Email); foreach (Users use in my_use) { use.Password = mod.NewPass.ToString(); } ent.SaveChanges(); Cache.gen_lock.ReleaseMutex(); ModelState.AddModelError("הצליח", "שינוי פרטים הצליח"); return(View(mod)); } else { ModelState.AddModelError("שגיאה", "פרטים לא נכונים, אנא וודא את השדות ושלח שוב"); return(View(mod)); } } }
public ActionResult ResetPassword(string id) { ResetPassModel model = new ResetPassModel { Id = id }; return(View(model)); }
public ActionResult Edit(string id) { ResetPassModel ViewModel = new ResetPassModel() { Id = id }; return(View(ViewModel)); }
public ActionResult ResetPassword(string key) { ResetPassModel mod = new ResetPassModel(); mod.Id = ""; mod.Key = key; mod.Email = ""; mod.NewPass = ""; return(View(mod)); }
public ActionResult ResetPassword(ResetPassModel model) { if (ModelState.IsValid) { if (UserService.FindById(model.Id) == null) { HttpNotFound(); } UserService.ResetPass(model.Id, model.Password); } return(RedirectToAction("Login", "Account")); }
public ActionResult Edit(ResetPassModel model) { if (ModelState.IsValid) { UserService.ResetPass(model.Id, model.Password); return(RedirectToAction("AllUsers", "Admin")); } else { ModelState.AddModelError("", "Заполните поля"); } return(View()); }
public async Task <MessageReport> ResetPass(ResetPassModel model) { var result = new MessageReport(false, "Có lỗi xảy ra"); try { //Kiểm tra tài khoản tồn tại var user = await GetById(model.UserId); if (user == null) { result = new MessageReport(false, "Tài khoản không tồn tại"); return(await Task.FromResult(result)); } //Giải mã pass var depass = CryptoHelper.DecryptPass_User(user.Password, user.PasswordSalat); if (depass != model.OldPass) { result = new MessageReport(false, "Mật khẩu cũ không khớp"); return(await Task.FromResult(result)); } //Update pass mới user.PasswordSalat = Guid.NewGuid().ToString(); user.Password = CryptoHelper.EncryptPass_User(model.NewPass, user.PasswordSalat); var query = new StringBuilder(); query.AppendLine("{"); query.AppendLine("'_id': { '$eq': '" + model.UserId + "' }"); query.AppendLine("}"); result = await _SY_UserRepository.Update(MongoHelper.ConvertQueryStringToDocument(query.ToString()), user); } catch (System.Exception ex) { result = new MessageReport(false, ex.Message); } return(await Task.FromResult(result)); }
public async Task <MessageReport> ResetPass(ResetPassModel model) { var result = new MessageReport(false, "Có lỗi xảy ra"); try { //Kiểm tra tài khoản tồn tại var user = await GetById(model.UserId); if (user == null) { result = new MessageReport(false, "Tài khoản không tồn tại"); return(await Task.FromResult(result)); } //Giải mã pass var depass = CryptoHelper.DecryptPass_User(user.Password, user.PasswordSalat); if (depass != model.OldPass) { result = new MessageReport(false, "Mật khẩu cũ không khớp"); return(await Task.FromResult(result)); } //Update pass mới user.PasswordSalat = Guid.NewGuid().ToString(); user.Password = CryptoHelper.EncryptPass_User(model.NewPass, user.PasswordSalat); result = await _SY_UserRepository.Update(user); } catch (System.Exception ex) { result = new MessageReport(false, ex.Message); } return(await Task.FromResult(result)); }
public ActionResult SavePassword(ResetPassModel m) { if (!ModelState.IsValid) { return(View("ChangePassword", m)); } if (m.MatKhauMoi != m.XacNhanMatKhau || m.MatKhauMoi.Trim().Length == 0) { ModelState.AddModelError("XacNhanMatKhau", "Xác nhận mật khẩu mới không trùng nhau."); return(View("ChangePassword", m)); } TaiKhoan user = (TaiKhoan)Session["User"]; var existed = db.TaiKhoans.FirstOrDefault(o => o.MaTaiKhoan == user.MaTaiKhoan); if (existed == null) { return(RedirectToAction("Logout", "Login")); } if (EncryptHelper.GenerateSHA256String(m.MatKhau) != existed.MatKhau) { ModelState.AddModelError("MatKhau", "Sai mật khẩu hiện tại."); return(View("ChangePassword", m)); } existed.MatKhau = EncryptHelper.GenerateSHA256String(m.MatKhauMoi.Trim()); db.SaveChanges(); TempData["Message"] = "Đổi mật khẩu thành công."; return(RedirectToAction("UserProfile")); }
public async Task <MessageReport> reset([FromBody] ResetPassModel model) { return(await _AuthService.ResetPass(model)); }