| Line | Revision | Contents |
| 1 | 1 | #!/usr/bin/php |
| 2 | <?php |
|
| 3 | 14.1.84 | // $Id: password-hash.sh,v 1.4 2009/01/13 22:39:11 dries Exp $ |
| 4 | 1 | |
| 5 | /** |
|
| 6 | * Drupal hash script - to generate a hash from a plaintext password |
|
| 7 | * |
|
| 8 | * Check for your PHP interpreter - on Windows you'll probably have to |
|
| 9 | * replace line 1 with |
|
| 10 | * #!c:/program files/php/php.exe |
|
| 11 | * |
|
| 12 | * @param password1 [password2 [password3 ...]] |
|
| 13 | 14.1.84 | * Plain-text passwords in quotes (or with spaces backslash escaped). |
| 14 | 1 | */ |
| 15 | ||
| 16 | function variable_get($x, $default) { |
|
| 17 | return $default; |
|
| 18 | } |
|
| 19 | ||
| 20 | if (version_compare(PHP_VERSION, "5.2.0", "<")) { |
|
| 21 | $version = PHP_VERSION; |
|
| 22 | echo <<<EOF |
|
| 23 | ||
| 24 | 14.1.14 | ERROR: This script requires at least PHP version 5.2.0. You invoked it with |
| 25 | 1 | PHP version {$version}. |
| 26 | \n |
|
| 27 | EOF; |
|
| 28 | exit; |
|
| 29 | } |
|
| 30 | ||
| 31 | $script = basename(array_shift($_SERVER['argv'])); |
|
| 32 | ||
| 33 | if (in_array('--help', $_SERVER['argv']) || empty($_SERVER['argv'])) { |
|
| 34 | echo <<<EOF |
|
| 35 | ||
| 36 | Generate Drupal password hashes from the shell. |
|
| 37 | ||
| 38 | Usage: {$script} [OPTIONS] "<plan-text password>" |
|
| 39 | Example: {$script} "mynewpassword" |
|
| 40 | ||
| 41 | All arguments are long options. |
|
| 42 | ||
| 43 | --help Print this page. |
|
| 44 | ||
| 45 | --root <path> |
|
| 46 | ||
| 47 | Set the working directory for the script to the specified path. |
|
| 48 | To execute this script this has to be the root directory of your |
|
| 49 | Drupal installation, e.g. /home/www/foo/drupal (assuming Drupal |
|
| 50 | running on Unix). Use surrounding quotation marks on Windows. |
|
| 51 | ||
| 52 | "<password1>" ["<password2>" ["<password3>" ...]] |
|
| 53 | ||
| 54 | One or more plan-text passwords enclosed by double quotes. The |
|
| 55 | output hash may be manually entered into the {users}.pass field to |
|
| 56 | change a password via SQL to a known value. |
|
| 57 | ||
| 58 | To run this script without the --root argument invoke it from the root directory |
|
| 59 | of your Drupal installation as |
|
| 60 | ||
| 61 | ./scripts/{$script} |
|
| 62 | \n |
|
| 63 | EOF; |
|
| 64 | exit; |
|
| 65 | } |
|
| 66 | ||
| 67 | $passwords = array(); |
|
| 68 | ||
| 69 | // Parse invocation arguments. |
|
| 70 | while ($param = array_shift($_SERVER['argv'])) { |
|
| 71 | switch ($param) { |
|
| 72 | case '--root': |
|
| 73 | // Change the working directory. |
|
| 74 | $path = array_shift($_SERVER['argv']); |
|
| 75 | if (is_dir($path)) { |
|
| 76 | chdir($path); |
|
| 77 | } |
|
| 78 | break; |
|
| 79 | default: |
|
| 80 | // Add a password to the list to be processed. |
|
| 81 | $passwords[] = $param; |
|
| 82 | break; |
|
| 83 | } |
|
| 84 | } |
|
| 85 | ||
| 86 | define('DRUPAL_ROOT', getcwd()); |
|
| 87 | ||
| 88 | include_once DRUPAL_ROOT . '/includes/password.inc'; |
|
| 89 | include_once DRUPAL_ROOT . '/includes/common.inc'; |
|
| 90 | ||
| 91 | foreach ($passwords as $password) { |
|
| 92 | print("\npassword: $password \t\thash: ". user_hash_password($password) ."\n"); |
|
| 93 | } |
|
| 94 | print("\n"); |
|
| 95 |
Loggerhead 1.17 is a web-based interface for Bazaar branches