PHP Password hashing

This script uses the PASSWORD_DEFAULT algorithm for hashing, which is currently BCRYPT, and may change over time as new and stronger algorithms are added to PHP. If you want to use a specific algorithm, you can replace PASSWORD_DEFAULT with PASSWORD_BCRYPT, PASSWORD_ARGON2I, or PASSWORD_ARGON2ID depending on your PHP version.

Please note that this script assumes that each line in your text file contains one piece of data to be hashed. If your data is structured differently, you may need to adjust the script accordingly.

Also, remember to handle your hashed passwords securely and responsibly! 😊

<?php
// Specify the file to read from and the file to write to
$inputFile = 'data.txt';
$outputFile = 'hashed_data.txt';

// Check if the input file exists
if (!file_exists($inputFile)) {
    die("The file $inputFile does not exist");
}

// Open the input file for reading and the output file for writing
$inputHandle = fopen($inputFile, 'r');
$outputHandle = fopen($outputFile, 'w');

if ($inputHandle && $outputHandle) {
    while (($line = fgets($inputHandle)) !== false) {
        // Remove newline characters
        $line = trim($line);

        // Hash the line using password_hash and write it to the output file
        $hashedLine = password_hash($line, PASSWORD_DEFAULT);
        fwrite($outputHandle, $hashedLine . "\n");
    }

    // Close the file handles
    fclose($inputHandle);
    fclose($outputHandle);

    echo "Pass: Hashing completed successfully";
} else {
    echo "Fail: Error opening files";
}
?>