For all of my hobby web projects, I have coded a login system that these project
ID: 659477 • Letter: F
Question
For all of my hobby web projects, I have coded a login system that these projects share. There is no critical data in these projects, the only critical data could be reused passwords. So I try to hash passwords in a very secure way.
My current password hashing algorithm is nothing I would call really secure. And as I saw that PHP now offers build in hashing with password_hash, I thought about switching.
My question is, what are the benefits of switching for me? In terms of, what extra protection do I get, what hole(s) do I fix, etc.? And is there anything else I have to do to not make it extremely insecure?
I would like to use the answers as a learning experience for myself so I can teach it to others who are in my position.
My current algorithm (pseudo-code):
Salt = "some-salt"
Repeat 1000000 times
Password = Sha512(Salt + username + Salt + Password)
I know my site is vulnerable to timing attacks and the PHP built-in functions would fix that.
What else is obviously insecure?
Explanation / Answer
For starters you rolled your own piece of password hashing algorithm. There are currently but three password hashing algorithms which are considered secure:
You are iterating and you are appending a salt. You also seem to add the username within the algorithm, which does not add any benefit as you are already using a salt.
What I can't deduct from your code and which is very important is the length of your salt and how you generate it. A salt should never be hardcoded, but secure randomly generated when hashing the password. The salt should be unique within the database and preferably globally unique as to avoid identification of similar passwords in different databases (hence a username is not considered a good salt).
Also the way PBKDF2 works (which leans closest to your implementation) is by using a HMAC where the random generated salt is the key used to calculate the message digest, rather than appending everything together. PHP's password_hash is using the bcrypt algorithm.
So to summarize what you gain by using a standard algorithm instead of your own:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.