neue_kennwoerter.txt // // Dr.Edgar Huckert 11-2010, 05-2022 // -------------------------------------------------- // Returns a rando vales as string function makeRandom() { $salt = ""; for ($i=0; $i <= 32; $i++) { $d = rand(1,30) % 2; $salt .= $d ? chr(rand(65,90)) : chr(rand(48,57)); } return $salt; } // end makeRandom() // --------------------------------------------------- // Returns a MD5 hash from the given string function makeHash($inp) { $line = trim($inp); $hashed = md5($inp); return $hashed; } // end makeHash() // --------------------------------------------------- // start of "main" program here $file = "pw_unencrypted.txt"; if (file_exists ($file)) { try { if ($fh = fopen ($file, "r")) { //echo "File ".$file." opened successfully.\n"; for ($line = fgets($fh); ! feof($fh); $line = fgets($fh)) { $line = trim($line); //print "read:".$line."\n"; $zufall = makeRandom(); $newPassword = makeHash($line.$zufall); //print "MD5 hashed: ".$newPassword."\n"; print $newPassword."\n"; } fclose($fh); } else { throw new exception ("Sorry, the file could not be opened\n\n"); } } catch (exception $e) { echo $e->getmessage(); } } else { echo "File ".$file. " does not exist\n\n"; } ?>