password-hash.sh

Same filename and directory in other branches
  1. 10 core/scripts/password-hash.sh
  2. 11.x core/scripts/password-hash.sh
  3. 9 core/scripts/password-hash.sh
  4. 8.9.x core/scripts/password-hash.sh
  5. 7.x scripts/password-hash.sh

Drupal hash script - to generate a hash from a plaintext password.

@todo Port to a console command. https://www.drupal.org/node/2289409

File

core/scripts/password-hash.sh

View source
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * @file
  5. * Drupal hash script - to generate a hash from a plaintext password.
  6. *
  7. * @todo Port to a console command. https://www.drupal.org/node/2289409
  8. */
  9. use Drupal\Core\DrupalKernel;
  10. use Symfony\Component\HttpFoundation\Request;
  11. if (PHP_SAPI !== 'cli') {
  12. return;
  13. }
  14. $script = basename(array_shift($_SERVER['argv']));
  15. if (in_array('--help', $_SERVER['argv']) || empty($_SERVER['argv'])) {
  16. echo <<
  17. Generate Drupal password hashes from the shell.
  18. Usage: {$script} [OPTIONS] ""
  19. Example: {$script} "my-new-password"
  20. All arguments are long options.
  21. --help Print this page.
  22. "" ["" ["" ...]]
  23. One or more plaintext passwords enclosed by double quotes. The
  24. output hash may be manually entered into the
  25. {users_field_data}.pass field to change a password via SQL to a
  26. known value.
  27. EOF;
  28. exit;
  29. }
  30. // Password list to be processed.
  31. $passwords = $_SERVER['argv'];
  32. $autoloader = require __DIR__ . '/../../autoload.php';
  33. $request = Request::createFromGlobals();
  34. $kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod', FALSE);
  35. $kernel->boot();
  36. $password_hasher = $kernel->getContainer()->get('password');
  37. foreach ($passwords as $password) {
  38. print("\npassword: $password \t\thash: " . $password_hasher->hash($password) . "\n");
  39. }
  40. print("\n");

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.