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