Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create encrypted hash passwords for drupal 7

After searching over internet I came to know that With drupal 7, password are no more encrypted through md5.

What are possible ways to get passwords encrypted in Drupal 7??

like image 203
M Arif Avatar asked Apr 24 '14 07:04

M Arif


3 Answers

With drupal 7, password are no more encrypted through md5. There are several way to get/set a password in drupal7. Using drush (for your information, not used in your case):

drush upwd admin --password="newpassword"

Without drush, if you have a cli access to the server : (for your information, not used in your case)

cd <drupal root directory>

php scripts/password-hash.sh 'myPassword'

Now copy the resultant hash and paste it into the query:

update users set name='admin', pass='pasted_big_hash_from_above' where uid=1;
like image 142
Malik Shahzad Avatar answered Nov 13 '22 13:11

Malik Shahzad


Thanks Malik.

After search I found different solutions. Following solution also works

If you are working on a remote environment on which you cannot connect, you can put this specified code in a file such as password.php such as this one:

<?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.";

And then hit your site using: http://domain.tld/password.php?p='MyPassword'. The hash will appear on your browser's tab. Don't forget to remove it once you done it. So, if you want to use some password function generation, have a look on _password_crypt() and _password_generate_salt()

like image 39
M Arif Avatar answered Nov 13 '22 12:11

M Arif


The user_hash_password() function can be used to hash password, if you want to use it outside from outside Drupal, you need to bootstrap Drupal configuration.

chdir("/path/to/drupal");
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
user_hash_password($password);
like image 3
Pierre Buyle Avatar answered Nov 13 '22 12:11

Pierre Buyle