Competing orders in a magnetic field: Spin and charge order in the cuprate superconductors