What are the potential security risks of using unencrypted passwords in PHP login systems?

Storing passwords in plain text in PHP login systems poses a significant security risk as it allows malicious actors to easily access and misuse user credentials if the database is compromised. To mitigate this risk, passwords should be securely hashed using algorithms like bcrypt before storing them in the database.

// Hashing the password before storing it in the database
$password = $_POST['password'];
$hashed_password = password_hash($password, PASSWORD_BCRYPT);

// Storing the hashed password in the database
$stmt = $pdo->prepare("INSERT INTO users (username, password) VALUES (:username, :password)");
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', $hashed_password);
$stmt->execute();