This tutorial is for a download center, but it is the same concept:
http://www.webassist.com/tutorials/How-to-create-a-download-center
The idea is that you need to force them to login before checkout so you can store their userid in the orders table. Then you can filter based on that userid to find their orders and display an order history when they log in again.