Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Drupal's default password encryption method?

Tags:

php

mysql

drupal

I am trying to figure out what is the security that Drupal 6/7 uses by default to store passwords. Is it MD5, AES, SHA? I have been unable to find anything.

like image 597
Chris Abrams Avatar asked Feb 17 '11 16:02

Chris Abrams


People also ask

What password encryption does Drupal 8 uses?

Drupal core uses a version of the Portable PHP password hashing framework that has been modified to use the SHA-512 algorithm instead of MD5.

What encryption is used for passwords?

Passwords are encrypted by the AES128 algorithm before they are stored in the directory and are retrieved as part of an entry in the original clear format. Passwords are encrypted by the AES192 algorithm before they are stored in the directory and are retrieved as part of an entry in the original clear format.

What is a password hashing?

Hashing turns your password (or any other piece of data) into a short string of letters and/or numbers using an encryption algorithm. If a website is hacked, cyber criminals don't get access to your password. Instead, they just get access to the encrypted “hash” created by your password.


2 Answers

Drupal 8 and Drupal 7 use SHA512 by default with a salt. They run the hash through PHP's hash function numerous times to increase the computation cost of generating a password's final hash (a security technique called stretching).

With Drupal 8, the implementation is object oriented. There is a PasswordInterface which defines a hash method. The default implementation of that interface is in the PhpassHashedPassword class. That class' hash method calls the crypt method passing in SHA512 as the hashing algorithm, a password, and a generated salt. The class' crypt method is nearly the same as Drupal 7's _password_crypt() method.

With Drupal 7, the implementation is split into a couple global functions: user_hash_password() and _password_crypt().

Drupal 6 uses MD5 without a salt. The relevant function is user_save().

like image 144
CalebD Avatar answered Sep 22 '22 04:09

CalebD


Here is an example hash from Drupal 7:

  • "pass" : "$S$Dxl65W9p07LfQU7jvy5CnsyDpMoLujiAgzy123khcg1OJi/P9pKS"

  • The characters 0-2 are the type ( $S$ is Drupal 7 )

  • The character 3 is the number of log2 rounds (X) based on the position of the char in this list: './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' So in our example 'D' would map to 15
  • The characters 4-11 are the SALT
  • The rest is a SHA512 hash using 2^X rounds.
  • The binary result is then converted to a string using base64.

    $count = 1 << $count_log2;
    $hash = hash($algo, $salt . $password, TRUE);
    do { $hash = hash($algo, $hash . $password, TRUE);
    } while (--$count);

The whole process can be found in: mydrupalsite\includes\password.inc

like image 28
Ray Hulha Avatar answered Sep 23 '22 04:09

Ray Hulha