What are the best practices for securely storing passwords in a database using MD5 encryption?

Storing passwords in a database using MD5 encryption is not recommended as MD5 is considered a weak hashing algorithm. It is better to use stronger algorithms like bcrypt or Argon2 for password hashing.

// Using bcrypt for password hashing
$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', $username);
$stmt->bindParam(':password', $hashed_password);
$stmt->execute();