Same filename and directory in other branches
  1. 8.9.x core/scripts/password-hash.sh
  2. 9 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> </div> </div> </div> </div> </div> <!-- /#content --> </div> <!-- /#column-left --> <div id="aside" role="complementary" > <div id="aside-region"> <div class="region region-sidebar-second"> <div id="search" class="block block-api"> <div class="block-inner"> <h2>Search Drupal 10.3</h2> <div class="content"> <form class="api-search-form" action="/api/drupal/core%21scripts%21password-hash.sh/8.6.x" method="post" id="api-search-form" accept-charset="UTF-8"><div><div class="form-item form-type-textfield form-item-search"> <label class="element-invisible" for="edit-search">Function, class, file, topic, etc. <span class="form-required" title="This field is required.">*</span></label> <input class="api-search-keywords form-text required form-autocomplete" type="text" id="edit-search" name="search" value="" size="60" maxlength="128" /><input type="hidden" id="edit-search-autocomplete" value="https://api.drupal.org/index.php?q=api/search/autocomplete/106" disabled="disabled" class="autocomplete" /> <div class="description">Partial match search is supported</div> </div> <input type="submit" id="edit-submit" name="op" value="Search" class="form-submit" /><input type="hidden" name="form_build_id" value="form-emtuy7Bfd4I0DUtID7ilPeUKEExclgQTBHeWUAtQk7s" /> <input type="hidden" name="form_id" value="api_search_form" /> </div></form> </div> </div> </div> </div> </div> <!-- /#column-right-region --> </div> <!-- /#column-right --> </div> </div> <!-- /#page --> <div id="footer" role="contentinfo"> <div class="region region-footer"> <div id="block-drupalorg-crosssite-drupalorg-footer" class="block block-drupalorg-crosssite"> <div class="block-inner"> <div class="content"> <h4 class="element-invisible">News items</h4><ul class="drupal-news"><li class="0 first"><a href="https://www.drupal.org/news">News</a></li> <li class="1"><a href="https://www.drupal.org/planet" title="News from Drupal community members">Planet Drupal</a></li> <li class="2"><a href="https://www.drupal.org/about/media-kit/social-media" title="Drupal on social media">Social media</a></li> <li class="3"><a href="https://www.drupal.org/subscribe">Sign up for Drupal news</a></li> <li class="4"><a href="https://www.drupal.org/security" title="Announcements from the Drupal Security Team">Security advisories</a></li> <li class="5 last"><a href="https://jobs.drupal.org/" title="Drupal Jobs">Jobs</a></li> </ul><h4 class="element-invisible">Our community</h4><ul class="community"><li class="0 first"><a href="https://www.drupal.org/community">Community</a></li> <li class="1"><span><a href="https://www.drupal.org/drupal-services" title="People and organizations offering Drupal services">Services</a>, <a href="https://www.drupal.org/training" title="People and organizations offering Drupal training">Training</a> & <a href="https://www.drupal.org/hosting" title="Organizations offering Drupal hosting">Hosting</a></span></li> <li class="2"><a href="https://www.drupal.org/community/contributor-guide">Contributor guide</a></li> <li class="3"><a href="https://groups.drupal.org/groups" title="groups.drupal.org">Groups &amp; meetups</a></li> <li class="4"><a href="https://events.drupal.org" title="Upcoming and past DrupalCons">DrupalCon</a></li> <li class="5 last"><a href="https://www.drupal.org/dcoc" title="Drupal code of conduct">Code of conduct</a></li> </ul><h4 class="element-invisible">Documentation</h4><ul class="get-started"><li class="0 first"><a href="https://www.drupal.org/documentation" title="Documentation for working with Drupal">Documentation</a></li> <li class="1"><a href="https://www.drupal.org/docs">Drupal Guide</a></li> <li class="2"><a href="https://www.drupal.org/docs/user_guide/en/index.html">Drupal User Guide</a></li> <li class="3"><a href="https://www.drupal.org/documentation/develop">Developer docs</a></li> <li class="4 last"><a href="https://api.drupal.org/" title="Drupal API reference">API.Drupal.org</a></li> </ul><h4 class="element-invisible">Drupal code base</h4><ul class="download-extend"><li class="0 first"><a href="https://www.drupal.org/download">Download &amp; Extend</a></li> <li class="1"><a href="https://www.drupal.org/project/drupal" title="Download the latest version of the Drupal software">Drupal core</a></li> <li class="2"><a href="https://www.drupal.org/project/project_module" title="Download add-on features and functionality">Modules</a></li> <li class="3"><a href="https://www.drupal.org/project/project_theme" title="Download pre-designed styles for Drupal">Themes</a></li> <li class="4 last"><a href="https://www.drupal.org/project/project_distribution" title="Download a pre-packaged Drupal site">Distributions</a></li> </ul><h4 class="element-invisible">Governance of community</h4><ul class="about"><li class="0 first"><a href="https://www.drupal.org/about">About</a></li> <li class="1"><a href="https://www.drupal.org/about/features/accessibility" title="Our committment to accessibility">Web accessibility</a></li> <li class="2"><a href="https://www.drupal.org/association" title="About the Drupal Association">Drupal Association</a></li> <li class="3"><a href="https://www.drupal.org/drupalorg" title="About Drupal.org">About Drupal.org</a></li> <li class="4"><a href="https://www.drupal.org/terms" title="Drupal.org terms of service">Terms of service</a></li> <li class="5 last"><a href="https://www.drupal.org/privacy" title="Drupal.org privacy policy">Privacy policy</a></li> </ul> </div> </div> </div> <div id="block-block-3" class="block block-block"> <div class="block-inner"> <div class="content"> <p>All source code and documentation on this site is released under the terms of the <a href="http://api.drupal.org/api/file/LICENSE.txt">GNU General Public License, version 2 and later</a>. <a href="https://www.drupal.org/">Drupal</a> is a <a href="https://www.drupal.org/about/trademark">registered trademark</a> of <a href="https://dri.es">Dries Buytaert</a>.</p> </div> </div> </div> </div> </div> <script type="text/javascript"> (function(){ window._pxAppId = 'PXVnPBBfwe'; window._pxParam2 = ''; window._pxParam3 = '0'; var p = document.getElementsByTagName('script')[0], s = document.createElement('script'); s.async = 1; s.src = '/VnPBBfwe/init.js'; p.parentNode.insertBefore(s,p); }()); </script> <noscript> <div style="position:fixed; top:0; left:0; display:none" width="1" height="1"> <img src="/VnPBBfwe/xhr/api/v1/collector/noScript.gif?appId=PXVnPBBfwe"> </div> </noscript></body> </html>