How does the use of crypt() function in PHP compare to the password_hash() function in terms of security and best practices?

The use of the crypt() function in PHP is considered outdated for password hashing due to its limited security features and susceptibility to various attacks. It is recommended to use the password_hash() function instead, which provides a more secure and reliable way to hash passwords using modern algorithms like bcrypt. This ensures better protection of user credentials and follows best practices in password security.

// Using password_hash() for secure password hashing
$password = "secret_password";
$hashed_password = password_hash($password, PASSWORD_DEFAULT);