What potential security risks are associated with storing user credentials in a text file in PHP?

Storing user credentials in a text file in PHP poses a significant security risk as the file can be easily accessed by unauthorized users. It is recommended to store user credentials securely using methods like hashing and salting to protect sensitive information. Additionally, using a database with proper encryption techniques is a more secure way to store user credentials.

<?php
// Hashing and salting user password before storing it in a text file
$password = "user_password";
$salt = "random_salt";
$hashed_password = hash('sha256', $password . $salt);

// Storing hashed password in a text file
$file = fopen("credentials.txt", "w");
fwrite($file, $hashed_password);
fclose($file);
?>