What is the purpose of encrypting passwords with MD5 in PHP?

Encrypting passwords with MD5 in PHP helps to securely store user passwords in a database by converting them into a fixed-length hash value. This process adds an extra layer of security by making it harder for attackers to retrieve the original password from the hash value. However, it's important to note that MD5 is considered to be a weak hashing algorithm, and stronger alternatives like bcrypt or Argon2 should be used for better security.

$password = 'password123';
$hashed_password = md5($password);
echo $hashed_password;