2011-02-17 60 views
39

我想弄清楚默认情况下Drupal 6/7使用哪些安全性来存储密码。它是MD5,AES,SHA吗?我一直无法找到任何东西。什么是Drupal的默认密码加密方法?

+5

” _I已经无法找到任何东西。“ - 好吧,通常,我不会'你试过谷歌'的评论,但这是荒谬的 - 你甚至找到了什么东西?(提示:将你的问题标题复制并粘贴到谷歌搜索框) – 2011-02-17 18:03:57

+14

我做了,它把我带到了堆栈溢出。:) – 2012-07-26 23:41:42

回答

64

Drupal 8和Drupal 7默认使用SHA512和盐。他们通过PHP的hash函数多次运行散列来增加生成密码的最终散列(一种称为stretching的安全技术)的计算成本。

随着Drupal 8,实现是面向对象的。有一个PasswordInterface它定义了一个哈希方法。该接口的默认实现位于PhpassHashedPassword类中。该类'hash方法调用传入SHA512的crypt方法作为哈希算法,密码和生成的盐。该类的crypt方法与Drupal 7的_password_crypt()方法几乎相同。

使用Drupal 7,实现分为几个全局函数:user_hash_password()_password_crypt()

Drupal 6使用不含盐的MD5。相关功能是user_save()

27

下面是从Drupal 7的一个例子的散列:

  • “通”: “$ S $ Dxl65W9p07LfQU7jvy5CnsyDpMoLujiAgzy123khcg1OJi/P9pKS”

  • 字符0-2是类型($ S $是Drupal的7)

  • 字符3是基于该焦炭在这个列表中的位置的log 2轮(X)的数量:所以在我们的例子‘d’将映射到15
  • “./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz”
  • 字符4-11是SALT
  • 其余的是使用2^X轮的SHA512哈希。
  • 然后使用base64将二进制结果转换为字符串。

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

整个过程可以发现: mydrupalsite \包括\ password.inc

10

它可以在里面WWW \检查包括\ password.inc

function user_check_password($password, $account) { 
    if (substr($account->pass, 0, 2) == 'U$') { 
    // This may be an updated password from user_update_7000(). Such hashes 
    // have 'U' added as the first character and need an extra md5(). 
    $stored_hash = substr($account->pass, 1); 
    $password = md5($password); 
    } 
    else { 
    $stored_hash = $account->pass; 
    } 

    $type = substr($stored_hash, 0, 3); 
    switch ($type) { 
    case '$S$': 
     // A normal Drupal 7 password using sha512. 
     $hash = _password_crypt('sha512', $password, $stored_hash); 
     break; 
    case '$H$': 
     // phpBB3 uses "$H$" for the same thing as "$P$". 
    case '$P$': 
     // A phpass password generated using md5. This is an 
     // imported password or from an earlier Drupal version. 
     $hash = _password_crypt('md5', $password, $stored_hash); 
     break; 
    default: 
     return FALSE; 
    } 
    return ($hash && $stored_hash == $hash); 
} 

它被写清楚“//使用sha512的正常Drupal 7密码。“

0

drupal的8是使用Phpass(修改后的版本)

Drupal 7的使用SHA-512 +盐

drupal的6和前一版本被使用MD5无盐