Example #1
0
 public JsonResult ChangePassword(string oldPassword, string newPassword)
 {
     if (string.IsNullOrEmpty(oldPassword))
     {
         return(Json(new { Error = 1, Message = "請輸入舊密碼" }));
     }
     if (string.IsNullOrEmpty(newPassword))
     {
         return(Json(new { Error = 1, Message = "請輸入新密碼" }));
     }
     try
     {
         var          oldPass      = MD5Hash.GetMd5String(oldPassword);
         AdminUserBLL adminUserBll = new AdminUserBLL();
         var          oriPass      = adminUserBll.GetPassHashByUserID(UserID);
         if (!string.Equals(oriPass, oldPass, StringComparison.OrdinalIgnoreCase))
         {
             return(Json(new { Error = 1, Message = "舊密碼錯誤" }));
         }
         var flag = adminUserBll.UpdatePassWordByUserID(UserID, newPassword);
         if (flag)
         {
             return(Json(new { Error = 0 }));
         }
         else
         {
             return(Json(new { Error = 1, Message = "密碼修改失敗" }));
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error(ex);
         return(Json(new { Error = 1, Message = ex.Message }));
     }
 }