Brief layout of strategy:
Write down Lorentz forceLorentz force ${\bf F}$.
Find (velocity-dependent) potential $U$ for ${\bf F}$.
Write down Lagrangian $L$Lagrangian $L=T-U$.
Define the canonical (as opposed to kinetic/mechanical) momentum ${\bf p}:=\frac{\partial L}{\partial{\bf v}}$.
Perform Legendre transformationLegendre transformation ${\bf v}\to {\bf p}$.
Write down Hamiltonian $H$$H={\bf v}\cdot{\bf p}-L$.