我有一个本地服务器,它连接到我的在线数据库。我一直在使用bitAuth作为我的身份验证方法,并且它工作得非常好,直到我将所有文件都移到我的服务器上。
BitAuth附带默认管理员帐户admin(pw admin)。我尝试使用它来登录,但它返回“无效的用户名/密码”。
我看到其他人提到了类似的问题here,但没有任何解决方案。
答案 0 :(得分:1)
自己解决了:
我首先跟踪了BitAuth使用的密码验证过程。
这将带您进入这段代码:
function CheckPassword($password, $stored_hash)
{
$hash = $this->crypt_private($password, $stored_hash);
if ($hash[0] == '*')
$hash = crypt($password, $stored_hash);
return $hash == $stored_hash;
}
如果要打印$ hash和$ stored_hash,你会发现2个哈希值不同。(正如预期的那样,因为如果它是相同的那么登录就会通过)
此时,唯一可能的原因是crypt_private()函数产生的哈希值与存储的哈希值不同。然后我查看了crypt_private()函数:
function crypt_private($password, $setting)
{
$output = '*0';
if (substr($setting, 0, 2) == $output)
$output = '*1';
$id = substr($setting, 0, 3);
# We use "$P$", phpBB3 uses "$H$" for the same thing
if ($id != '$P$' && $id != '$H$')
return $output;
$count_log2 = strpos($this->itoa64, $setting[3]);
if ($count_log2 < 7 || $count_log2 > 30)
return $output;
$count = 1 << $count_log2;
$salt = substr($setting, 4, 8);
if (strlen($salt) != 8)
return $output;
# We're kind of forced to use MD5 here since it's the only
# cryptographic primitive available in all versions of PHP
# currently in use. To implement our own low-level crypto
# in PHP would result in much worse performance and
# consequently in lower iteration counts and hashes that are
# quicker to crack (by non-PHP code).
if (PHP_VERSION >= '5') {
$hash = md5($salt . $password, TRUE);
do {
$hash = md5($hash . $password, TRUE);
} while (--$count);
} else {
$hash = pack('H*', md5($salt . $password));
do {
$hash = pack('H*', md5($hash . $password));
} while (--$count);
}
$output = substr($setting, 0, 12);
$output .= $this->encode64($hash, 16);
return $output;
}
似乎没有什么不合适的地方。然后我发现PHP可以在不同版本中产生不同的哈希值。然后我联系了我的服务器支持,发现服务器使用的是PHP5.2,而我的服务器使用的是PHP5.4。
solution很简单,我将以下行添加到CodeIgniter中的.htaccess文件中,
AddHandler application / x-httpd-php53 .php
在我的服务器中,将启用PHP5.3而不是PHP5.2。这使得crypt_private()函数从提供的密码字符串中使用存储的哈希生成相同的哈希值。
此问题的另一个解决方案是,基本上可以创建一个新帐户,进入您的数据库并“激活”该帐户。由于这个新哈希是由您的服务器使用的任何版本的PHP生成的,因此它解决了这个问题。
我希望我提供的2个解决方案可以帮助那些面临同样问题的其他BitAuth用户。
BitAuth是一个很棒的身份验证库,只要他们将这个放入他们的文档中,以使用户意识到这个潜在的错误。
美好的一天。