Starting note: After going through some articles and answers posted on SO related to storing secured passwords I'm still not sure whether my way of thinking is applicable to todays reality.
I'm currently thinking of a way to provide a secure structure for storing and retrieving passwords needed for authentication of a user on a webpage. While browsing the net and digging through pages of answers I've found myself stuck at some point. First of all, time goes on and not every article/answer is up to date. Secondly, there are many ambiguities as of what actually should be done.
I'm using PHP5 and Postgres database. While being aware of existance of pg_crypto module to me it seems like doing those computations on database level does not seem secure due to logging and passing plain password to database query.
So I decided to get the job done in application code (PHP). Since PHP5 there is a native password hashing API providing functions like password_hash()
and password_verify()
.
What I'm asking for is advice whether or not I'm on the right track or any improvements that could be done supported by strong security-related arguments (please refrain from advising on iterating milion times). Also, is this possible using PHP5 or am I missing any theoretical knowledge as well (considering my way of thinking for this process).
My way of thinking for this process is to:
- Get the password from user
- Apply a randomly generated salt for each user (preferably constant length for every salt), that is independent of any data stored in database
- Store that salt in table where users and their hashed passwords are going to be
- "Hashinng"
- Hash the salt concatenated with password using SHA512 algorithm
password_hash
with bcrypt
- Store hash in db
So as you can see my main consideration is whether to use SHA-512 or bcrypto, but I feel like I lack the capacity in this field and thus am asking for general advices to my entire process.
Particularly my attention to which "hashing" process to use was brought by erickson's answer on comparing SHA vs Bcrypt. I'm aware of SHA3 existance, but doesn't that prove there were things that should be improved as compared with SHA2 family (this is a question of type for now)?
What I've read already:
Non-random salt for password hashes
SHA512 vs. Blowfish and Bcrypt
Secure hash and salt for PHP passwords
Passwords storage, hash() with sha-512 or crypt() with blowfish (bcrypt)?