Magnetic field dependence of the critical current of a layered superconductor