How does the use of SHA enhance password security compared to MD5 in PHP?

Using SHA instead of MD5 enhances password security because SHA generates a more secure hash compared to MD5. SHA algorithms have longer hash values and are less prone to collisions, making it harder for attackers to crack passwords using brute force or rainbow table attacks.

// Using SHA-256 to hash passwords in PHP
$password = "password123";
$hashed_password = hash('sha256', $password);