Bonesnap wrote:I wouldn't use MD5 or SHA1. Instead I would use nothing less than SHA256 (SHA512 is my preference).
In the long (but probably not too long) run, SHA256 and SHA512 are not much better than MD5 or SHA1 for this purpose. I believe that even MD5 is still resistant to preimage attacks, hence MD5 for this purpose is theoretically as good as SHA512 right now, as long as your users choose sufficiently good passwords (but we know they won't).
Better options for this would be methods specifically designed for this purpose, e.g., PBKDF2, bcrypt or scrypt.
Bonesnap wrote:Your salt should be just as long as your password hash (again I use SHA512), and should be very random (a simple mt_rand(getrandmax()) is not good enough).
I think that that is a misconception: increasing the length of the salt by hashing it does not add to security since it does not change the entropy and the attacker is assumed to know the salt anyway; he/she does not need to know the input of the hash function. The salt should be unique, not just unique on your system but everywhere, hence the purpose of using a random value rather than say, the auto-incrementing integer primary key of the users table. Hence, I would argue that mt_rand(getrandmax()) is "good enough", though there is negligible cost to go beyond this "good enough" and hence you should.
NZ_Kiwis wrote:so if each user has a their own "salt" where do I keep that so i can reuse that when i compare the password when they login?
As dalecosp mentioned, one option is to store it in its own field in the database. As Weedpacket noted, the salt, or a hash from which the salt is derived, can be stored along with the hashed password, e.g., some common schemes use a '$' to separate the salt from the hashed password, then store them together in the same database field.
NZ_Kiwis wrote:storing it in the users table seems pointless
No, it would be sensible: the salt is part of the information required for authentication, hence storing it in the users table along with the username and hashed password is a good idea. Perhaps you say it is pointless because it would defeat the security that you are after, but the ideal properties of any appropriate hash function used (or password hashing scheme thereof) is such that the salt value can be revealed to an attacker without compromising security.