Created
April 11, 2026 14:42
-
-
Save andyg2/0d426cd98d888e250c0affabbee0eac5 to your computer and use it in GitHub Desktop.
Generate a mosquitto passwd file with iter=101, 12-byte salt (matching mosquitto_passwd 2.0.x)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Generate a passwd file with iter=101, 12-byte salt (matching mosquitto_passwd 2.0.x) | |
| $user = getenv('MQTT_USER'); | |
| $pass = getenv('MQTT_PASSWORD'); | |
| $iter = 101; | |
| $salt = random_bytes(12); | |
| $hash = hash_pbkdf2('sha512', $pass, $salt, $iter, 64, true); | |
| $line = $user . ':$7$' . $iter . '$' . base64_encode($salt) . '$' . base64_encode($hash); | |
| echo $line . PHP_EOL; | |
| file_put_contents('/mosquitto-data/passwd', $line . PHP_EOL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment