I need some help understanding how password are used to authenticate who you are and thereby allow you, the user, to have access to the appropriate data.
I have read these two articles over here: https://stackoverflow.com/questions/549/the-definitive-guide-to-form-based-website-authentication
and basically my questions sort of flow from these articles. I am going to try and summarize what I think it is saying as part of my attempt to understand.
1.User creates a password (say "123456" is the password, I know that is a terrible password).
2. The server uses a key derivation function with a salt and iterations to create a key for that user to encrypt that user's data. So say for example we use PBKDF2.
After the key derivation, I know we should not store the passwords themselves as plaintext. But I am not sure what to do next.
Specifically in one of the articles I read, the author said this
A cryptographic hash should not be used for password storage because user-selected passwords are not strong enough (i.e. do not usually contain enough entropy) and a password guessing attack could be completed in a relatively short time by an attacker with access to the hashes. This is why a KDF is used - these effectively "stretch the key" meaning that each password guesses an attacker makes involves iterating the hashing algorithm multiple times, for example, 10,000 times, making the attacker's password guessing 10,000 times slower.
Does this mean that instead of hashing the plaintext password (e.g. hashing 123456), the server instead hashes the key generated by running PBKDF2? So is the third step then to hash the keys?
Because the other article says something a bit different. The other article says
We need to hash passwords as a second line of defence. A server which can authenticate users necessarily contains, somewhere in its entrails, some data which can be used to validate a password.
Once the password has been created, say the user wants to end the session for whatever application is on. Say he wants to get on the application the next day. He enters his username and password. Are the following the correct steps taken when the user wants to authenticate who he is?
- User enters password.
- Server runs key-derivation on that password
- Server hashes the key with the particular hashing algorithm
- Server calls the hashed key for this particular username from the database.
- The output of steps 3 and 4 are compared. If they match, then the user is authenticated, otherwise denied.