Chris@0
|
1 #!/usr/bin/env php
|
Chris@0
|
2 <?php
|
Chris@0
|
3
|
Chris@0
|
4 /**
|
Chris@14
|
5 * @file
|
Chris@0
|
6 * Drupal hash script - to generate a hash from a plaintext password
|
Chris@0
|
7 *
|
Chris@0
|
8 * @param password1 [password2 [password3 ...]]
|
Chris@0
|
9 * Plain-text passwords in quotes (or with spaces backslash escaped).
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 use Drupal\Core\DrupalKernel;
|
Chris@0
|
13 use Symfony\Component\HttpFoundation\Request;
|
Chris@0
|
14
|
Chris@0
|
15 if (PHP_SAPI !== 'cli') {
|
Chris@0
|
16 return;
|
Chris@0
|
17 }
|
Chris@0
|
18
|
Chris@0
|
19 if (version_compare(PHP_VERSION, '5.4.5') < 0) {
|
Chris@17
|
20 $version = PHP_VERSION;
|
Chris@0
|
21 echo <<<EOF
|
Chris@0
|
22
|
Chris@0
|
23 ERROR: This script requires at least PHP version 5.4.5. You invoked it with
|
Chris@0
|
24 PHP version {$version}.
|
Chris@0
|
25 \n
|
Chris@0
|
26 EOF;
|
Chris@0
|
27 exit;
|
Chris@0
|
28 }
|
Chris@0
|
29
|
Chris@0
|
30 $script = basename(array_shift($_SERVER['argv']));
|
Chris@0
|
31
|
Chris@0
|
32 if (in_array('--help', $_SERVER['argv']) || empty($_SERVER['argv'])) {
|
Chris@0
|
33 echo <<<EOF
|
Chris@0
|
34
|
Chris@0
|
35 Generate Drupal password hashes from the shell.
|
Chris@0
|
36
|
Chris@0
|
37 Usage: {$script} [OPTIONS] "<plan-text password>"
|
Chris@0
|
38 Example: {$script} "mynewpassword"
|
Chris@0
|
39
|
Chris@0
|
40 All arguments are long options.
|
Chris@0
|
41
|
Chris@0
|
42 --help Print this page.
|
Chris@0
|
43
|
Chris@0
|
44 "<password1>" ["<password2>" ["<password3>" ...]]
|
Chris@0
|
45
|
Chris@0
|
46 One or more plan-text passwords enclosed by double quotes. The
|
Chris@0
|
47 output hash may be manually entered into the
|
Chris@0
|
48 {users_field_data}.pass field to change a password via SQL to a
|
Chris@0
|
49 known value.
|
Chris@0
|
50
|
Chris@0
|
51
|
Chris@0
|
52 EOF;
|
Chris@0
|
53 exit;
|
Chris@0
|
54 }
|
Chris@0
|
55
|
Chris@0
|
56 // Password list to be processed.
|
Chris@0
|
57 $passwords = $_SERVER['argv'];
|
Chris@0
|
58
|
Chris@0
|
59 $autoloader = require __DIR__ . '/../../autoload.php';
|
Chris@0
|
60
|
Chris@0
|
61 $request = Request::createFromGlobals();
|
Chris@0
|
62 $kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod', FALSE);
|
Chris@0
|
63 $kernel->boot();
|
Chris@0
|
64
|
Chris@0
|
65 $password_hasher = $kernel->getContainer()->get('password');
|
Chris@0
|
66
|
Chris@0
|
67 foreach ($passwords as $password) {
|
Chris@14
|
68 print("\npassword: $password \t\thash: " . $password_hasher->hash($password) . "\n");
|
Chris@0
|
69 }
|
Chris@0
|
70 print("\n");
|