What are the advantages of storing passwords in a database table compared to directly in PHP files?
Storing passwords directly in PHP files is not secure because if someone gains access to the files, they can easily view the passwords. It is recommended to store passwords in a database table where they can be encrypted for added security.
// Connect to database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
$conn = new mysqli($servername, $username, $password, $dbname);
// Encrypt password before storing in database
$password = password_hash($password, PASSWORD_DEFAULT);
// Store password in database
$sql = "INSERT INTO users (username, password) VALUES ('$username', '$password')";
$conn->query($sql);
$conn->close();