I want to implement a salt into my login system but am a bit confused on how this is supposed to work. I can\'t understand the logic behind it. I understand md5 is a one-way
Hashing passwords is meant to keep those passwords secret from your own administrator(s).
1) Keeping plain text passwords in your database would be fine except your passwords may be used by the administrator to gain access to some other system.
2) You can use a single global salt, which is combined with the passwords (by prepending or XORing them) and then hashing for storage in the database. But that is vulnerable to a malicious administrator AND a rainbow table designed for that one salt.
3) You can have a separate salt for each user: The database will be used to store the salt, and the hash derived from the password/salt combination. This will prevent a rainbow attack, but brute force attacks will still be possible.
4) Finally, you can keep your hash function a secret by using a velocity-limited hardware hashing solution.
That is as good as you can do. Because of human nature, passwords have a limited domain and are vulnerable to brute force attacks. We are trying to prevent administrators getting a hold of user passwords, and then using them on other systems they should not have access to.
Some other notes:
a) You can use bcrypt on the password/salt combination to slow down the attacker’s brute force attack. But since we are assuming administrators, they can be patient.
b) Keeping the salt separate from the password hash is not an effective defense, we are assuming administrators after all.
c) Using existing data as a salt is a little better, but I doubt existing data has as much entropy a random salt has.