What are some common mistakes or misunderstandings that beginners encounter when working with password hashing in PHP?

One common mistake beginners encounter when working with password hashing in PHP is not using a strong hashing algorithm like bcrypt. Another mistake is not salting the passwords before hashing them, which adds an extra layer of security. It's also important to securely store the hashed passwords in a database to prevent unauthorized access.

// Using bcrypt for password hashing
$options = [
    'cost' => 12,
];
$hashed_password = password_hash($password, PASSWORD_BCRYPT, $options);

// Salting the password before hashing
$salt = uniqid(mt_rand(), true);
$hashed_password = password_hash($salt . $password, PASSWORD_DEFAULT);

// Storing hashed password securely in a database
// Example query using PDO
$stmt = $pdo->prepare("INSERT INTO users (username, password) VALUES (:username, :password)");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $hashed_password);
$stmt->execute();