What are the advantages of using password_hash() over md5 for hashing passwords in PHP applications?

Using password_hash() over md5 for hashing passwords in PHP applications is advantageous because password_hash() uses stronger and more secure hashing algorithms (such as bcrypt or Argon2) which are specifically designed for securely hashing passwords. This helps protect against brute-force attacks and rainbow table attacks. Additionally, password_hash() automatically generates a unique salt for each password hash, making it more secure than using a static salt like with md5.

$password = 'password123';
$hashed_password = password_hash($password, PASSWORD_DEFAULT);