#! /usr/bin/php = 3) { echo ("Add the obfuscated line below to Mosquitto's password file to authenticate with the provided credentials:\n\n"); echo (mosquitto_password($argv[1], $argv[2])."\n"); } else { echo("ERROR: Supply username and password as arguments in that order.\n"); } function mosquitto_password($username, $password) { $salt_base64 = base64_encode(openssl_random_pseudo_bytes(12)); // $salt_base64="mfJ0Eq3rIDLKG33r"; // example salt used in blog post $salt = base64_decode($salt_base64); $hash = hash("sha512", $password.$salt, true); $hash_base64 = base64_encode($hash); return($username.":$6$".$salt_base64."$".$hash_base64); } ?>