Avatar ·

Secure hashing and salt for passwords in PHP: how to do it right?

Hello everyone. I'm a beginner PHP developer, and I have a problem with storing user passwords. Currently I'm using simple md5(), but I read that it's not secure. I tried adding a salt, but I'm not sure I'm doing it correctly.\n\nHere's my current code for registration:\n\n```php\n$password = $_POST['password'];\n$salt = 'my_secret_salt';\n$hashed_password = md5($salt . $password);\n// saving $hashed_password to DB\n```\n\nAnd for verification during login:\n\n```php\n$password = $_POST['password'];\n$salt = 'my_secret_salt';\n$hashed_password = md5($salt . $password);\n// comparing with what's in DB\n```\n\nProblems I see:\n1. The salt is static — if it gets exposed, all passwords are compromised.\n2. md5() is too fast, it's easy to brute-force.\n3. No protection against timing attacks (timing a