Php BitAuth实时服务器错误

Php BitAuth实时服务器错误,php,codeigniter,authentication,Php,Codeigniter,Authentication,我有一个本地服务器,它连接到我的在线数据库。我一直在使用bitAuth作为身份验证方法,在我将所有文件移动到服务器之前,它工作得非常好 BitAuth附带一个默认管理员帐户admin(pw admin)。我尝试使用此登录,但它返回“无效用户名/密码” 我看到其他人提到了类似的问题,但没有任何解决方案。自己解决了: 我首先跟踪了BitAuth使用的密码验证过程 这将为您带来这段代码: function CheckPassword($password, $stored_hash) { $ha

我有一个本地服务器,它连接到我的在线数据库。我一直在使用bitAuth作为身份验证方法,在我将所有文件移动到服务器之前,它工作得非常好

BitAuth附带一个默认管理员帐户admin(pw admin)。我尝试使用此登录,但它返回“无效用户名/密码”

我看到其他人提到了类似的问题,但没有任何解决方案。

自己解决了:

我首先跟踪了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_散列,您会发现这两个散列是不同的。(正如预期的那样,因为如果是相同的,那么登录就会通过)

此时,唯一可能的原因是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;
}
函数crypt\u private($password,$setting)
{
$output='*0';
if(substr($setting,0,2)=$output)
$output='*1';
$id=substr($setting,0,3);
#我们使用“$P$”,phpBB3使用“$H$”表示相同的内容
如果($id!='$P$'&&$id!='$H$')
返回$output;
$count_log2=strpos($this->itoa64,$setting[3]);
如果($count_log2<7||$count_log2>30)
返回$output;
$count=1='5'){
$hash=md5($salt.$password,TRUE);
做{
$hash=md5($hash.$password,TRUE);
}而(-$count);
}否则{
$hash=pack('H*',md5($salt.$password));
做{
$hash=pack('H*',md5($hash.$password));
}而(-$count);
}
$output=substr($setting,0,12);
$output.=$this->encode64($hash,16);
返回$output;
}
似乎没有什么不合适的地方。然后我想到PHP可以在不同的版本中生成不同的哈希。然后我联系了我的服务器支持人员,发现服务器使用的是PHP5.2,而我的服务器使用的是PHP5.4

这很简单,我在CodeIgniter的.htaccess文件中添加了以下行

AddHandler应用程序/x-httpd-php53.php

在我的服务器中,它将启用PHP5.3而不是PHP5.2。这使得crypt_private()函数从提供的密码字符串中生成与存储的哈希相同的哈希

这个问题的另一个解决方案是,可以创建一个新帐户,进入数据库并“激活”该帐户。因为这个新的散列是由服务器使用的任何版本的PHP生成的,所以它解决了这个问题

我希望我提供的两个解决方案能够帮助其他面临同样问题的BitAuth用户

BitAuth是一个很好的身份验证库,只要他们将其放入文档中,让用户意识到这个潜在错误就行了


早安。

确保用户属于某些组。。最近我在这方面遇到了困难。是的,用户确实属于组“admin”:/删除用户身份验证。然后编辑用户密码。。还要确保pswd如doc所说是正确的..它不是解决方案。我已经完全解决了这个问题,并在下面添加了一个答案。