snipt

Ctrl+h for KB shortcuts

PHP

Reset drupal 7 password using php file

<?php
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 
require_once 'includes/password.inc';
echo user_hash_password('pw');
 
die();
menu_execute_active_handler(); ?>

Description

if you're stuck working on a drupal project with no ssh or drush.

set your 'pw' in the file and then run the script in your browser. copy and paste the output into the 'pass' field of your users table in the user entry you want to reset.

make sure you remove the file or remove the traces of your password when you're done!
https://snipt.net/embed/19b0bd7b101a22fd96777e8104bff3e1/
/raw/19b0bd7b101a22fd96777e8104bff3e1/
19b0bd7b101a22fd96777e8104bff3e1
php
PHP
10
2019-06-18T23:44:01
True
False
False
Jul 29, 2013 at 09:52 AM
/api/public/snipt/70183/
reset-drupal-password-using-php-file
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nb">define</span><span class="p">(</span><span class="s1">&#39;DRUPAL_ROOT&#39;</span><span class="p">,</span> <span class="nb">getcwd</span><span class="p">());</span> </span><span id="L-3"><a name="L-3"></a><span class="k">require_once</span> <span class="nx">DRUPAL_ROOT</span> <span class="o">.</span> <span class="s1">&#39;/includes/bootstrap.inc&#39;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="nx">drupal_bootstrap</span><span class="p">(</span><span class="nx">DRUPAL_BOOTSTRAP_FULL</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="k">require_once</span> <span class="s1">&#39;includes/password.inc&#39;</span><span class="p">;</span> </span><span id="L-7"><a name="L-7"></a><span class="k">echo</span> <span class="nx">user_hash_password</span><span class="p">(</span><span class="s1">&#39;pw&#39;</span><span class="p">);</span> </span><span id="L-8"><a name="L-8"></a> </span><span id="L-9"><a name="L-9"></a><span class="k">die</span><span class="p">();</span> </span><span id="L-10"><a name="L-10"></a><span class="nx">menu_execute_active_handler</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"drupal 7", drupal, mysql, password, reset