便携式(PHPass)密码哈希。我应该使用它们吗? [英] Portable (PHPass) password hashes. Should I use them?

查看:179
本文介绍了便携式(PHPass)密码哈希。我应该使用它们吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的网站安装了用户注册脚本(Tank Auth)。



在安装指南中,


警告:默认情况下,库生成强大的系统特定的
密码散列,不可移植。
这意味着一旦创建,用户
数据库不能被转储和导出
到另一个服务器。这个行为也可以在配置文件中改变


这让我陷入两难境地。在未来,我可能想改变服务器,但我不想要弱密码。可移植密码哈希是否具有很大的风险?更重要的是,它们是什么意思是哈希?是否为字符长度?

解决方案

(旧版本,这不是一个好的标志;您可能希望在安装时更新)。 PHPass有两种模式,portable和bcrypt。



根据PHP版本,你不需要有便携式哈希。在PHP 5.3及以上版本中,PHP提供自己的bcrypt实现,如果它在系统上不可用。 如果所有服务器都有PHP 5.3及更高版本,我强烈建议关闭便携式散列。 PHPassportables hashes存在,因为根据安装的PHP版本,bcrypt可能不可用。 p>

也就是说,PHPass便携式散列将盐存储在其哈希中。这就是为什么每次运行相同的密码是不同的。



此外,PHPass在生成这些哈希期间使用 PHP_VERSION * 以检查该版本的 md5()函数是否支持 $ rawMode 参数。如果没有, pack()用于将十六进制数据转换为二进制(注意,这是相当慢,只是使用 $ rawMode ,这就是为什么分支)。



再次,如果所有的服务器都运行PHP 5.3及以上,我强烈建议关闭便携模式,并让PHPass使用 bcrypt 。由于PHP 5.3+提供了自己的实现,当系统不可用时,您的散列将可以跨操作系统检查。即使你关闭了便携模式,PHPass仍然能够聪明地检查你的旧哈希值正确的方式。



*第131行 / p>




EDIT:下面介绍如何生成便携模式下的哈希值不使用在PHPass中发现的实际变量,但精确)。注意,PHPass使用自己的base64编码版本。


  1. $ final ='$ P $'


  2. $ final。= encode64_int($ rounds) ,PHP 5+上最低为5,另外3个)


  3. $ final。= genSalt() (Salt是6字节... 8字节的encode64格式)。


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


  5. 2 $ rounds $ hash = md5($ hash。$ password)


  6. $ final = encode64($ hash)


p>

  $ P $ 9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0 
\ __________ / \ ____________________ /
\ \
\ \实际散列
\
\ $ P $ 9 IQRaTwmf
\_ / \ \ ______ /
\ \ \
\ \ \ Salt
\ \
\ \#舍入(不是十进制表示,9实际上是11)
\
\散列头


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?

解决方案

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

这篇关于便携式(PHPass)密码哈希。我应该使用它们吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆