【问题标题】:What is Drupal's default password encryption method?Drupal 的默认密码加密方法是什么?
【发布时间】:2011-06-29 05:38:04
【问题描述】:

我试图弄清楚 Drupal 6/7 默认使用什么安全性来存储密码。是 MD5、AES、SHA 吗?我一直找不到任何东西。

【问题讨论】:

  • "我找不到任何东西。" - 好的,通常情况下,我不做'你试过谷歌' cmets,但这很荒谬 - 你有没有甚至尝试找到什么? (提示:将您的问题标题复制并粘贴到谷歌搜索框中)
  • 我做到了。它把我带到了 Stack Overflow。 :)

标签: php mysql drupal


【解决方案1】:
【解决方案2】:

对于 Drupal 6 核心,该方法使用 MD5,据我了解,没有使用任何盐分。对于 drupal 7,使用了一些更高级的散列。这里有一篇很好的文章 - http://joncave.co.uk/2011/01/password-storage-in-drupal-and-wordpress/

【讨论】:

  • Drupal 6 不再被社区支持,但是有一个贡献的模块可以让 Drupal 6 成为核心我们更强大的 PHPASS 机制:drupal.org/project/phpass
【解决方案3】:

drupal 8 正在使用 Phpass(修改版)

drupal 7 使用 SHA-512 + 盐

drupal 6 和以前的版本使用没有盐的 md5

【讨论】:

    【解决方案4】:

    可以在 www\includes\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 密码。”

    【讨论】:

      【解决方案5】:

      这里是 Drupal 7 的示例哈希:

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

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

      • 字符 3 是基于此列表中字符位置的 log2 轮数 (X): './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' 所以在我们的示例中,'D' 将映射到 15
      • 字符 4-11 是 SALT
      • 其余的是使用 2^X 轮的 SHA512 哈希。
      • 然后使用 base64 将二进制结果转换为字符串。

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

      整个过程可以在: mydrupalsite\includes\password.inc

      【讨论】:

        【解决方案6】:

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

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

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

        Drupal 6 使用没有盐的 MD5。相关函数为user_save()

        【讨论】:

        猜你喜欢
        • 2016-11-02
        • 2015-01-22
        • 1970-01-01
        • 2011-05-20
        • 2016-03-03
        • 1970-01-01
        • 1970-01-01
        • 2022-01-25
        • 1970-01-01
        相关资源
        最近更新 更多