public ActionResult ChangePassword(string ACCOUNT_Username, string OldPassword, string NewPassword, string ConfirmNewPassword) { if (ModelState.IsValid) { ACCOUNT aCCOUNT = new ACCOUNT(); var dao = new LoginDAO(); if (dao.CheckPassword(ACCOUNT_Username, dao.GetMD5(OldPassword))) { if (OldPassword != NewPassword) { if (NewPassword == ConfirmNewPassword) { aCCOUNT.ACCOUNT_Username = ACCOUNT_Username; aCCOUNT.ACCOUNT_Password = dao.GetMD5(NewPassword); var result = dao.UpdatePassword(aCCOUNT); if (result) { string content = System.IO.File.ReadAllText(Server.MapPath("~/Views/templates/ChangePassword.html")); content = content.Replace("{{username}}", ACCOUNT_Username); new MailHelper().SendMail(dao.GetByUsername(ACCOUNT_Username).ACCOUNT_Email, "University Magazine", content, "Authenticate information"); SetAlert("Password changed successfully!", "success"); } else { SetAlert("Password change failed!", "warning"); } } else { SetAlert("New passwords are not the same!", "warning"); } } else { SetAlert("Old password cannot match new password!", "warning"); } } else { SetAlert("Wrong password!", "warning"); } } return(RedirectToAction("Index")); }