public ActionResult ChanegAdminRegPassword(changePasswordModel model) { try { if (ModelState.IsValid) { using (var context = new JustHallAtumationEntities()) { var regPass = context.AdminRegistrionPasswords.Where(x => x.AdminRegPass.Length > 0).FirstOrDefault(); string RegPass = "******"; if (regPass != null) { RegPass = regPass.AdminRegPass; } if (model.currentPassword.Replace(" ", "") == RegPass.Replace(" ", "")) { if (regPass == null) { AdminRegistrionPassword adminRegistrionPassword = new AdminRegistrionPassword() { AdminRegPass = model.newPassword }; context.AdminRegistrionPasswords.Add(adminRegistrionPassword); } else { regPass.AdminRegPass = model.newPassword; } context.SaveChanges(); ViewBag.Success = "Succesfully Chanegd!"; } else { ViewBag.Success = "Current password don't match with admin registration password!"; } } } return(View()); } catch (Exception ex) { return(View(ex)); } }
public ActionResult ChangePassword(changePasswordModel model) { try { if (ModelState.IsValid) { using (var context = new JustHallAtumationEntities()) { string UserName = User.Identity.Name; var user = context.Users.Where(x => x.UserName == UserName).FirstOrDefault(); if (user != null) { if (user.Password != loginRegistrationOperation.HashFunction(model.currentPassword)) { ViewBag.Success = "Current Password doesn't match!"; } else { ViewBag.Success = "Successfull Changed your password!"; user.Password = loginRegistrationOperation.HashFunction(model.newPassword); context.SaveChanges(); } } else { ViewBag.Success = "Somethings Wrong!"; } } } return(View()); } catch (Exception ex) { return(View(ex)); } }