5 * Drupal hash script - to generate a hash from a plaintext password
7 * @param password1 [password2 [password3 ...]]
8 * Plain-text passwords in quotes (or with spaces backslash escaped).
11 use Drupal\Core\DrupalKernel;
12 use Symfony\Component\HttpFoundation\Request;
14 if (PHP_SAPI !== 'cli') {
18 if (version_compare(PHP_VERSION, '5.4.5') < 0) {
19 $version = PHP_VERSION;
22 ERROR: This script requires at least PHP version 5.4.5. You invoked it with
23 PHP version {$version}.
29 $script = basename(array_shift($_SERVER['argv']));
31 if (in_array('--help', $_SERVER['argv']) || empty($_SERVER['argv'])) {
34 Generate Drupal password hashes from the shell.
36 Usage: {$script} [OPTIONS] "<plan-text password>"
37 Example: {$script} "mynewpassword"
39 All arguments are long options.
41 --help Print this page.
43 "<password1>" ["<password2>" ["<password3>" ...]]
45 One or more plan-text passwords enclosed by double quotes. The
46 output hash may be manually entered into the
47 {users_field_data}.pass field to change a password via SQL to a
55 // Password list to be processed.
56 $passwords = $_SERVER['argv'];
58 $autoloader = require __DIR__ . '/../../autoload.php';
60 $request = Request::createFromGlobals();
61 $kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod', FALSE);
64 $password_hasher = $kernel->getContainer()->get('password');
66 foreach ($passwords as $password) {
67 print("\npassword: $password \t\thash: ". $password_hasher->hash($password) ."\n");