donglie1898 2011-03-17 18:35
浏览 99
已采纳

便携式(PHPass)密码哈希。 我应该使用它们吗?

I'm installing a user registration script (Tank Auth) for my website.

In the installation guide its says,

WARNING: By default the library generates strong system-specific password hashes that are not portable. It means that once created, user database cannot be dumped and exported to another server. This behavior can be changed in config-file as well.

This put me in a dilemma. In the future I may want to change servers but I don't want weak passwords either. Are portable password hashes a big risk? And more importantly, what do they mean by hashes? Is it the character length?

  • 写回答

1条回答 默认 最新

  • doucuyu2259 2011-03-17 18:39
    关注

    Task Auth uses PHPass for password hashing (an old version, that's not a good sign; you might want to update that in your install). PHPass has two modes, portable and bcrypt.

    Depending on the PHP version, you do not need to have portable hashes on. On PHP 5.3 and above, PHP supplies its own implementation of bcrypt if it isn't available on the system. If all your servers have PHP 5.3 and above, I highly recommend to turn portable hashes off. PHPass "portables hashes" exists because, depending of the version of PHP installed, bcrypt might not be available.

    That said, PHPass portable hashes does store the salt in its hash. That's why every run on the same password is different.

    Also, PHPass uses PHP_VERSION during the generation of those hashes* to check if the md5() function available with that version supports the $rawMode parameter. If it doesn't, pack() is use to transform the hexadecimal data into binary (note that this is considerably slower then simply using $rawMode, which is why the branch is made).

    Again, if all your servers are running PHP 5.3 and above, I highly recommend to turn off portable mode and let PHPass use bcrypt instead. Since PHP 5.3+ provides its own implementation when the system one isn't available, your hash will be checkable across OSes. Even if you do turn off portable mode, PHPass will still be smart enough to check your old hashes the proper way.

    * Line 131


    EDIT: For more explanation, here is how hashes in portable mode are generated (simplified, does not use actual variables found in PHPass, but accurate). Note that PHPass uses their own version of base64 encoding.

    1. $final = '$P$'

    2. $final .= encode64_int($rounds) (from constructor, minimum is 5 on PHP 5+, 3 other)

    3. $final .= genSalt() (Salt is 6 bytes... 8 bytes in "encode64" format).

    4. $hash = md5($salt . $password)

    5. For 2$rounds times, do $hash = md5($hash . $password)

    6. $final = encode64($hash)

    So the final hash essentially is this:

    $P$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0
    \__________/\____________________/
      \                   \
       \                   \ Actual Hash
        \
         \  $P$   9   IQRaTwmf
            \_/   \   \______/
             \     \      \
              \     \      \ Salt
               \     \ 
                \     \ # Rounds (not decimal representation, 9 is actually 11)
                 \
                  \ Hash Header
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。