Generate a Drupal Password Hash — Free Drupal 7 Format Generator
The Drupal Password Hash Generator reproduces Drupal 7's own password hashing scheme: enter a password, pick an iteration count — 15 (32,768 rounds) is Drupal 7's own default — and click Generate Hash to get a $S$-prefixed hash built from phpass-style stretching with SHA-512. The result is verified against Drupal core's own documented algorithm, so you can drop it straight into a Drupal 7 database. Running Drupal 8 or later? You actually want this site's Bcrypt Generator instead, since newer Drupal switched to PHP's standard bcrypt-based hashing.
Locked out of your Drupal site or scripting a bulk user import? The Drupal Password Hash Generator gives you a cryptographically correct, ready-to-paste hash in seconds — no host access, no runtime required. Whether you manage a legacy installation or a modern Drupal 9 or Drupal 10 site, understanding exactly how your CMS stores and validates credentials is the difference between a smooth recovery and hours of frustration. This tool replicates the internal user_hash_password() logic so you can generate password hash values outside of a live environment and apply them directly to the users table — making it the go-to drupal password hash generator for site administrators.
What Is the Drupal Password Hash Generator and How Does Platform Password Security Work?
Drupal is a powerful, open source platform written in a server-side scripting language, first released on January 15, 2000. As an open source php framework, it competes with platforms like WordPress and Joomla, but is widely recognised for its integrity, flexibility, and modularity — principles baked into its authentication implementation from the very beginning. The stable released version 8.4.2 marked a significant evolution in how the platform handled credential protection, and every version since has built on that foundation.
The system does not store any plain text password in its data store. Instead, it runs every credential through a cryptography-based algorithm — a one-way transformation rooted in cryptography that produces an encrypted result that cannot be reversed. When a user logs in, the platform re-hashes the supplied input and compares the resultant value to what is stored. This process of password validation and checking means that even if your database password records are compromised, attackers cannot decode values directly. The combination of salting and iterative transformation makes pre-hashed lists of candidate passwords — so-called rainbow table attacks — effectively useless against a properly configured installation.
Legacy Hash (v1.0 – v7) Using MD5 and SHA-512 — Understanding the Two Algorithms
The platform's credential-hashing has gone through two major eras. In the legacy hash scheme (v1.0 – v7), covering version 6 (d6), d5, and the entire v7 family, the platform relied on a phpass-based approach that layered iterative SHA-512 encoding with a random prefix over the older md5 foundation. Earlier releases — and d6 — used a simpler md5 update query that could reset a user's password with minimal protection. A bare md5 digest with no prefix offered very little resistance; an attacker with access to the users table could use a simple md5 lookup to recover credentials, which is precisely the improvement that the v7 release introduced by adding iterative SHA-512 processing.
In the legacy hash scheme, the algorithm calls the internal _password_crypt function, which accepts the algorithm identifier (sha512), the plain text password, and a generated prefix string. The prefix is produced by _password_generate_salt, which uses DRUPAL_HASH_COUNT to set the number of iterations. More iterations mean more computational work for anyone attempting a brute-force attack. The complete logic lives inside includes/password.inc (also referred to as password.inc), which is the core file responsible for all credential creation and validation in the v1.0 – v7 era.
A simple unsalted digest on a password would not satisfy the login validity check, because the random prefix prevents the ability to use pre-hashed lists of candidate passwords against your stored records. This is a critical point for any third-party application — such as one written in VB.NET — that tries to produce a compatible hashed password without going through the platform's own password function generation logic.
New Hash (v8 and Above) — SHA-512, hash_salt, and the password.inc Evolution
From version 8 onward — including Drupal 9, Drupal 10, and all future stable releases — the new hash scheme (v8 – new versions) introduced the site-wide hash_salt setting stored in your settings.php file. This hash salt string is a long random string, typically generated via the Drupal\Component\Utility\Crypt::randomBytesBase64(55) method and stored in the settings file as:
$settings['hash_salt'] = '4XvSLlsiNKrnVQ-mqPyPGJpD_j78Px2syLDDbgojRbyWM8DYm8vTXii5ZFh9U_WzoNRukpHs9A';This setting means that two different installations will produce different hashed passwords for the identical plain text password — the random string is site-specific. The user_hash_password() function (the successor to the legacy _password_crypt approach and now housed in password.php) incorporates both this global hash_salt and a per-password random string during hash generation. The result is a salted, hashed password that is resistant to both dictionary attacks and credential stuffing from other breached data stores. The iteration count (controlled by drupal_hash_count) defines how many loops the algorithm runs, balancing protection against host performance.
Because these outputs are one-way transformations, there is no way to decode values from the stored result — the highest level of protection the platform can offer. The only paths forward when you've lost access are to replace password hash values by writing a newly generated one directly to the data store, or to use a CLI utility or script to reset credentials through the terminal.
Reminder: After updating the pass column in the users or users_field_data table, always clear the cache. You can do this by runningDELETE FROM cache_entity WHERE cid = 'values:user:1' or by truncating table cache_entity entirely, since the v7 and v8 releases do not read the users field data table directly from disk on every request — cached entity data may persist and block your login.How to Apply Your Generated Password Hash in Drupal — SQL, Drush, and Script Methods
Once you use this drupal password hash generator to create a value, you have three primary paths to apply it: a direct SQL query against the user table (updating the database password field), a Drush command from the terminal, or a bootstrap script using web development framework APIs. Each method suits a different scenario — choose based on what CLI access or remote environment access you have available.
Updating the Hash Directly in the Data Store — SQL Against the users_field_data Table
The most direct method for recovering a locked-out administrator account is a query targeting uid=1. This approach works across every version and requires only data store access — no host-side runtime is needed.
- Generate the hash: Enter your desired newpassword in the tool above, select your version (Legacy for the v1.0 – v7 era or New Hash for v8/9/10), and copy the full output string produced.
- Back up your data store: Before modifying the user table directly, always export a full backup. A corrupted pass field will prevent all logins, so this is non-negotiable.
- Run the SQL UPDATE: Connect using phpMyAdmin, MySQL Workbench, or a direct MySQL CLI session and run the following update query:
update users set name='admin', pass='pasted_big_hash_from_above' where uid=1;For v8, v9, and v10 installations, the user data is split across two tables. You must also update the users_field_data table in addition to the base users table:
UPDATE users_field_data SET pass='pasted_big_hash_from_above' WHERE uid=1;After running the query, clear the cache entity table to ensure the system reads the updated credentials rather than a stale cached version. The user identifier for the primary administrator account is always uid=1, making this a reliable target for credential recovery across all installations.
Alternative Methods Using Drush Commands and the password-hash.sh Script
If you have terminal access to your host, the Drush utility provides the fastest path to reset credentials without touching the data store directly. The drush upwd command handles both the hash generation and the table update in a single operation:
drush upwd admin --password="newpassword"This command works for both the v1.0 – v7 era and modern releases. It internally calls user_hash_password(), applies the correct random prefix, and writes the result directly to the users table — removing the need to manually copy or paste values. It is the recommended approach whenever Drush is installed and available in your environment.
For the v7 era specifically, the scripts folder of your root directory contains the legacy password-hash.sh script. You can invoke this script directly from the terminal to generate a compatible drupal 7 password hash for any plain text input:
cd <drupal root directory>
php scripts/password-hash.sh 'myPassword'The password-hash.sh utility loads includes/bootstrap.inc and the password include file, calls the internal crypt function with the SHA-512 algorithm and the output of the salt generator, and prints the resulting string to stdout. You then copy that output and paste it into your SQL UPDATE statement. This scripted approach is ideal when Drush is not installed but you still have scripting access on the host.
For v10 environments where you need to generate a new random prefix string, use the following terminal evaluation command:
drush eval "echo Drupal\Component\Utility\Crypt::randomBytesBase64(55) . PHP_EOL"This invocation calls the Drupal\Component\Utility\Crypt utility (specifically crypt::randomBytesBase64) to produce 55 random bytes encoded as base64, giving you a new random string of sufficient entropy. Copy the output and paste it as the value of $settings['hash_salt'] in your settings.php file. The randombytesBase64 method generates cryptographically secure random bytes — the same source of entropy used during the original installation — so each string is unique and unpredictable. This is the recommended method for generating a new hash_salt in any v9 or v10 environment.
The terminal evaluation approach uses the drupal_component namespace and its utility crypt class, which supersedes the older bootstrap pattern from the v7 era. In modern releases, you no longer need to manually call the bootstrap configuration constant — the CLI tool handles that step automatically.
Programmatic Hashing with Bootstrap — For Bulk User Imports and Custom Scripts
When integrating user management with a third-party application — such as a VB.NET system, a RESTful service endpoint migration pipeline, or a custom user registration script — you need to produce encrypted results outside of the normal web request cycle. The bootstrap approach used in web development lets any script call the native password function without a full web request. For the v7 era, the pattern using the bootstrap include file and password include looks like this:
chdir("/path/to/drupal");
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
user_hash_password($password);For more surgical use — for example, a lightweight endpoint that accepts a password via GET and returns its output without triggering a full framework bootstrap — the following snippet (sometimes used in password implementation tooling) isolates just the credential-encoding logic via the password include file:
<?php
if (isset($_GET['p'])) {
require_once dirname(__FILE__) . '/includes/bootstrap.inc';
require_once dirname(__FILE__) . '/includes/password.inc';
print _password_crypt('sha512', $_GET['p'], _password_generate_salt(DRUPAL_HASH_COUNT));
exit();
}
print "No password to hash.";This script calls the internal crypt function directly with the SHA-512 algorithm and uses the salt generator to produce the per-password random string. The output is a salted result in the platform's own phpass-derived format — ready to be inserted into the pass column of the users table. Note that this pattern uses the bootstrap include file (loaded via require_once) to load the platform's constants, including the hash count constant, before calling the credential function. This is a clean way to perform bulk encoding without bootstrapping the full framework.
For bulk user import scenarios, you can either pre-generate values using this online tool and store them in a CSV or JSON payload, or use the bootstrap snippet above inside a migration script. In either case, the pass field written to the data store must contain the full output — including the algorithm prefix and iteration prefix characters — not a raw digest string. A third-party application that writes only a bare digest will cause authentication failures because the validation logic reads the prefix characters to determine how many iterations to apply during credential checking. The service interface or REST-based approach (using the platform's Services or JSON:API modules) is preferable for user register operations when you have the option, as it delegates hash generation and random string generation to the platform itself.
Note: Always treat yoursettings.php file and the hash_salt value it contains as highly sensitive configuration. Exposing your site's random prefix string gives attackers the information they need to pre-compute candidate passwords specific to your installation. Store the settings file outside the web root where possible, and restrict host file permissions so that only the web process user can read it. The random prefix setting is the cornerstone of your site's authentication integrity — protect it accordingly.Whether you are a backend developer in web development building an integration, a site administrator recovering access to the administrator account, or a DevOps engineer scripting user accounts through a third-party application, understanding the full credential implementation — from the md5-era approach through the iterative SHA-512 encoding of the drupal 7 password hash scheme to the site-wide hash_salt model of v8 and beyond — gives you the context to use this tool correctly and maintain the highest standards of password management and authentication across your entire ecosystem.
Frequently Asked Questions
- Does this match Drupal 8, 9, or 10's password hashes?
- No -- Drupal 8 and later switched to PHP's built-in password_hash() function, which uses bcrypt by default. That's exactly what this site's Bcrypt Generator produces, so use that tool instead if you're targeting Drupal 8+. This tool specifically replicates Drupal 7's own $S$-prefixed scheme.
- How does Drupal 7's algorithm work?
- It's structurally the same "stretched hash" approach as the classic phpass library (the same design WordPress's legacy $P$ hashes use), but with SHA-512 as the underlying hash instead of MD5: the password is combined with a random salt and hashed repeatedly (2^15 = 32,768 times by default), then the result is encoded with a custom base64-like alphabet and truncated to Drupal's fixed 55-character hash length.
- How was this verified to be correct?
- By fetching Drupal core's actual includes/password.inc source directly from Drupal's own GitHub repository and implementing the documented algorithm exactly as specified -- including a detail easy to get wrong (the full SHA-512 output is base64-encoded to 86 characters, then the combined string is truncated to exactly 55 characters, not encoded to 55 directly). Cross-checked byte-for-byte between an independent Python re-implementation and this tool's actual browser JavaScript before shipping.
- Can I insert this hash directly into a Drupal database?
- Yes -- the generated string matches the exact format Drupal 7's users table pass column expects, so it can be used directly in a manual database update or migration script for a Drupal 7 site.
- Is my password sent anywhere?
- No. The entire hash is computed locally using the Web Crypto API -- your password and the resulting hash are never transmitted to a server or stored.