Understanding planetary magnetic field and water retention