You are here

password-hash.sh in Drupal 9

Same filename and directory in other branches
  1. 8 core/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. /**
  3. * @file
  4. * Drupal hash script - to generate a hash from a plaintext password
  5. *
  6. * @param password1 [password2 [password3 ...]]
  7. * Plain-text passwords in quotes (or with spaces backslash escaped).
  8. *
  9. * @todo Port to a console command. https://www.drupal.org/node/2289409
  10. */
  11. use Drupal\Core\DrupalKernel;
  12. use Symfony\Component\HttpFoundation\Request;
  13. if (PHP_SAPI !== 'cli') {
  14. return;
  15. }
  16. $script = basename(array_shift($_SERVER['argv']));
  17. if (in_array('--help', $_SERVER['argv']) || empty($_SERVER['argv'])) {
  18. echo <<
  19. Generate Drupal password hashes from the shell.
  20. Usage: {$script} [OPTIONS] "" </li><li>Example: {$script} "my-new-password" </li><li> </li><li>All arguments are long options. </li><li> </li><li> --help Print this page. </li><li> </li><li> "<password1>" ["<password2>" ["<password3>" ...]] </li><li> </li><li> One or more plaintext passwords enclosed by double quotes. The </li><li> output hash may be manually entered into the </li><li> {users_field_data}.pass field to change a password via SQL to a </li><li> known value. </li><li> </li><li> </li><li>EOF; </li><li> exit; </li><li>} </li><li> </li><li>// Password list to be processed. </li><li>$passwords = $_SERVER['argv']; </li><li> </li><li>$autoloader = require __DIR__ . '/../../autoload.php'; </li><li> </li><li>$request = Request::createFromGlobals(); </li><li>$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod', FALSE); </li><li>$kernel->boot(); </li><li> </li><li>$password_hasher = $kernel->getContainer()->get('password'); </li><li> </li><li>foreach ($passwords as $password) { </li><li> print("\npassword: $password \t\thash: " . $password_hasher->hash($password) . "\n"); </li><li>} </li><li>print("\n"); </li></ol></code></pre></details> <div class="api-objects"> </div> </div></div> <!-- /.section, /#content --> <div id="sidebar-second" class="column sidebar"><div class="section"> <div class="region region-sidebar-second"> <div id="block-api-navigation" class="block block-api"> <h2>API Navigation</h2> <div class="content"> <div class="item-list"><ul><li class="first"><a href="/api/drupal/9">Drupal 9</a></li> <li><a href="/api/drupal/groups/9">Topics</a></li> <li><a href="/api/drupal/classes/9">Classes</a></li> <li><a href="/api/drupal/functions/9">Functions</a></li> <li><a href="/api/drupal/files/9">Files</a></li> <li><a href="/api/drupal/namespaces/9">Namespaces</a></li> <li><a href="/api/drupal/services/9">Services</a></li> <li><a href="/api/drupal/elements/9">Elements</a></li> <li><a href="/api/drupal/constants/9">Constants</a></li> <li><a href="/api/drupal/globals/9">Globals</a></li> <li class="last"><a href="/api/drupal/deprecated/9">Deprecated</a></li> </ul></div> </div> </div> </div> </div></div> <!-- /.section, /#sidebar-second --> </div></div> <!-- /#main, /#main-wrapper --> <div id="footer-wrapper"><div class="section"> <footer id="footer" role="contentinfo" class="clearfix"> <div class="region region-footer"> <div id="block-block-1" class="block block-block"> <div class="content"> <p><footer>Drupal is a registered trademark of Dries Buytaert. This site is not affiliated with Dries Buytaert, Drupal Association or Drupal.org.</footer></p> </div> </div> </div> </footer> <!-- /#footer --> </div></div> <!-- /.section, /#footer-wrapper --> </div></div> <!-- /#page, /#page-wrapper --> </body> </html> <!-- Page cached by Boost @ 2022-08-15 01:32:23, expires @ 2023-08-14 01:32:23, lifetime 12 months 4 days -->