I was going to write a tutorial, but it was too hard trying to explain OO concepts so I'm just going to release the script. Should be pretty secure. Also includes functions for validating an e-mail address and grabbing a user's IP address.
Any feedback/comments welcome, thanks.
I updated the script to include an install file and made a few other changes. File is too big to upload here so..