pastebin

Paste Search Dynamic
Recent pastes
drupal password hash
  1. #!/usr/bin/env php
  2. <?php
  3.  
  4. /**
  5.  * @file
  6.  * Drupal hash script - to generate a hash from a plaintext password
  7.  *
  8.  * @param password1 [password2 [password3 ...]]
  9.  *  Plain-text passwords in quotes (or with spaces backslash escaped).
  10.  */
  11.  
  12. use DrupalCoreDrupalKernel;
  13. use SymfonyComponentHttpFoundationRequest;
  14.  
  15. if (PHP_SAPI !== 'cli') {
  16.   return;
  17. }
  18.  
  19. if (version_compare(php_version, '5.4.5') < 0) {
  20.   $version = php_version;
  21.   echo <<<EOF
  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. EOF;
  51.   exit;
  52. }
  53.  
  54. // Password list to be processed.
  55. $passwords = $_SERVER['argv'];
  56.  
  57. $autoloader = require __DIR__ . '/../../autoload.php';
  58.  
  59. $request = Request::createFromGlobals();
  60. $kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod', false);
  61. $kernel->boot();
  62.  
  63. $password_hasher = $kernel->getContainer()->get('password');
  64.  
  65. foreach ($passwords as $password) {
  66.   print("npassword: $password tthash: " . $password_hasher->hash($password) . "n");
  67. }
  68. print("n");
Parsed in 0.087 seconds