The most secure way to store passwords is in such a way that even you (your app) doesn't know what the password is. This is accomplished by using a one way hash. As the name implies this is one way, there is no way to "un-hash" a hashed value and see what the original value was.
One of the important characteristics of a cryptographic hash is that hashing a value will always produce the same hash.The SHA-2 (256) hash of "The quick brown fox jumps over the lazy dog" will always generate a hash d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592
- while there is no way to take that hash and determine what the unhashed value is a hacker with a rainbow table could see what it corresponds to (this is why weak passwords, even when hashed are still vulnerable, every rainbow table in the world is going to have the hashes for 123456).
So before hashing the password we add a salt (ideally a different salt for each user). If before hashing "The quick brown fox jumps over the lazy dog" we add a salt (let's just use the word "salt" as a simple example) we would now hash "saltThe quick brown fox jumps over the lazy dog" and get b369837c6389d8dddb06cb669961b0ab80f5166cc8cebcfaf9734ed009c31e8b
as our hash.
The salted hash is what you should store (however/wherever makes sense for your application) and check against. So when a user first creates an account you will:
- take the password they choose and add the salt
- hash it (using a collision free cryptographic hash, such as SHA-2)
- store the result
When the user attempts to login you will:
- take the password they input into the login form and add the salt
- hash it
- compare it to what you have stored
If it is not identical they entered the incorrect password, if it is the same you know they entered the correct password and you can log them in.