6 * Drupal hash script - to generate a hash from a plaintext password
8 * @param password1 [password2 [password3 ...]]
9 * Plain-text passwords in quotes (or with spaces backslash escaped).
12 use Drupal\Core\DrupalKernel;
13 use Symfony\Component\HttpFoundation\Request;
15 if (PHP_SAPI !== 'cli') {
19 if (version_compare(PHP_VERSION, '5.4.5') < 0) {
20 $version = PHP_VERSION;
23 ERROR: This script requires at least PHP version 5.4.5. You invoked it with
24 PHP version {$version}.
30 $script = basename(array_shift($_SERVER['argv']));
32 if (in_array('--help', $_SERVER['argv']) || empty($_SERVER['argv'])) {
35 Generate Drupal password hashes from the shell.
37 Usage: {$script} [OPTIONS] "<plan-text password>"
38 Example: {$script} "mynewpassword"
40 All arguments are long options.
42 --help Print this page.
44 "<password1>" ["<password2>" ["<password3>" ...]]
46 One or more plan-text passwords enclosed by double quotes. The
47 output hash may be manually entered into the
48 {users_field_data}.pass field to change a password via SQL to a
56 // Password list to be processed.
57 $passwords = $_SERVER['argv'];
59 $autoloader = require __DIR__ . '/../../autoload.php';
61 $request = Request::createFromGlobals();
62 $kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod', FALSE);
65 $password_hasher = $kernel->getContainer()->get('password');
67 foreach ($passwords as $password) {
68 print("\npassword: $password \t\thash: " . $password_hasher->hash($password) . "\n");