Created
November 23, 2015 13:58
-
-
Save f1code/9557362e96e7cf96001f to your computer and use it in GitHub Desktop.
Script for generating WP secret keys (like https://api.wordpress.org/secret-key/1.1/salt/, but suitable to use in .env file)
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 | |
| function generate_salt($length) { | |
| $seed = 'abcdefghijklmnopqrstuvwxyz' | |
| .'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
| .'0123456789!@#$%^&*()"'; // and any other characters | |
| $rand = substr(str_shuffle(str_repeat($seed, $length)), 0, $length); | |
| return $rand; | |
| } | |
| function escape_value($val) { | |
| return '"' . preg_replace('/"|\\|\\$/', '\\\\$0', $val) . '"'; | |
| } | |
| function generate_all() { | |
| $keys = ['AUTH_KEY', | |
| 'SECURE_AUTH_KEY', | |
| 'LOGGED_IN_KEY', | |
| 'NONCE_KEY', | |
| 'AUTH_SALT', | |
| 'SECURE_AUTH_SALT', | |
| 'LOGGED_IN_SALT', | |
| 'NONCE_SALT']; | |
| $salts = []; | |
| foreach($keys as $k) { | |
| $salts[$k] = generate_salt(64); | |
| } | |
| return $salts; | |
| } | |
| function print_all($salts) { | |
| foreach($salts as $name => $val) { | |
| echo $name . '=' . escape_value($val) . "\n"; | |
| } | |
| } | |
| print_all(generate_all()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment