summaryrefslogtreecommitdiffstatshomepage
path: root/core/scripts/password-hash.sh
diff options
context:
space:
mode:
authorNathan Haug <nate@quicksketch.org>2011-10-30 16:32:37 -0700
committerNathaniel <catch@35733.no-reply.drupal.org>2011-11-01 12:48:40 +0900
commit06fb770bd340e5a18555e0da55a4dd6ba22f76ba (patch)
treee814bc08d51db3af473ae5be565219c0249b7870 /core/scripts/password-hash.sh
parent906a6db34707d27120dddd43a23f26f24153255d (diff)
downloaddrupal-06fb770bd340e5a18555e0da55a4dd6ba22f76ba.tar.gz
drupal-06fb770bd340e5a18555e0da55a4dd6ba22f76ba.zip
Issue #22336 by quicksketch, scor, boombatower, and rfay. Move all core Drupal files under a core subdirectory.
Diffstat (limited to 'core/scripts/password-hash.sh')
-rwxr-xr-xcore/scripts/password-hash.sh90
1 files changed, 90 insertions, 0 deletions
diff --git a/core/scripts/password-hash.sh b/core/scripts/password-hash.sh
new file mode 100755
index 00000000000..004421a896c
--- /dev/null
+++ b/core/scripts/password-hash.sh
@@ -0,0 +1,90 @@
+#!/usr/bin/php
+<?php
+
+/**
+ * Drupal hash script - to generate a hash from a plaintext password
+ *
+ * Check for your PHP interpreter - on Windows you'll probably have to
+ * replace line 1 with
+ * #!c:/program files/php/php.exe
+ *
+ * @param password1 [password2 [password3 ...]]
+ * Plain-text passwords in quotes (or with spaces backslash escaped).
+ */
+
+if (version_compare(PHP_VERSION, "5.2.0", "<")) {
+ $version = PHP_VERSION;
+ echo <<<EOF
+
+ERROR: This script requires at least PHP version 5.2.0. You invoked it with
+ PHP version {$version}.
+\n
+EOF;
+ exit;
+}
+
+$script = basename(array_shift($_SERVER['argv']));
+
+if (in_array('--help', $_SERVER['argv']) || empty($_SERVER['argv'])) {
+ echo <<<EOF
+
+Generate Drupal password hashes from the shell.
+
+Usage: {$script} [OPTIONS] "<plan-text password>"
+Example: {$script} "mynewpassword"
+
+All arguments are long options.
+
+ --help Print this page.
+
+ --root <path>
+
+ Set the working directory for the script to the specified path.
+ To execute this script this has to be the root directory of your
+ Drupal installation, e.g. /home/www/foo/drupal (assuming Drupal
+ running on Unix). Use surrounding quotation marks on Windows.
+
+ "<password1>" ["<password2>" ["<password3>" ...]]
+
+ One or more plan-text passwords enclosed by double quotes. The
+ output hash may be manually entered into the {users}.pass field to
+ change a password via SQL to a known value.
+
+To run this script without the --root argument invoke it from the root directory
+of your Drupal installation as
+
+ ./scripts/{$script}
+\n
+EOF;
+ exit;
+}
+
+$passwords = array();
+
+// Parse invocation arguments.
+while ($param = array_shift($_SERVER['argv'])) {
+ switch ($param) {
+ case '--root':
+ // Change the working directory.
+ $path = array_shift($_SERVER['argv']);
+ if (is_dir($path)) {
+ chdir($path);
+ }
+ break;
+ default:
+ // Add a password to the list to be processed.
+ $passwords[] = $param;
+ break;
+ }
+}
+
+define('DRUPAL_ROOT', getcwd());
+
+include_once DRUPAL_ROOT . '/includes/password.inc';
+include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
+
+foreach ($passwords as $password) {
+ print("\npassword: $password \t\thash: ". user_hash_password($password) ."\n");
+}
+print("\n");
+