You can do this a few different ways:
1) Boot into single user mode(assuming your grub install isn't set to boot in 0 seconds). To do this you'll need to stop grub and edit the boot options(E for Grub legacy or Ctrl+X for Grub2), find the line for the kernel and add 1 or single to the end or it. Then boot.
2) use your installation media(or a live Debian CD/DVD).
1. Boot it up, and get to a terminal(Ctrl+Alt+one of the F keys 1 - 5)
2. Make a directory to mount your root file system to and mount it there
3. mount --bind /dev [your root FS location]/dev
4. mount --bind /proc [your root FS location]/proc
5. mount --bind /sys [your root FS location]/sys
6. chroot [your root FS location]
7. Run your passwd command and anything else you need to do before rebooting
8. make sure you exit from the chroot before trying to issue the reboot command
3) Use another Linux system to generate the encrypted password, mount the root file system from any live CD or installation CD and use vi(or whatever text editor) to modify your shadow file