坦克身份验证在不同的系统(Mac和Linux)创建不同的密码哈希代码



我使用mac作为Web服务器,并使用codeigniter作为框架。为了进行身份验证,我应用了坦克身份验证。出现一个问题:

之前:我使用mac作为网络服务器,登录很好。

现在:我使用 linux 作为 Web 服务器。我导入了相同的数据库,网站运行良好。但是,我无法登录。

所以我测试了在mac和linux中使用相同的密码注册,发现它创建了不同的密码哈希代码。

Linux:

$P$Bh3B8uGDw0yGO1e/ytCUw2jXcswkso1

苹果电脑:

$2a$08$jBCiR79fHN6xzOw5sB09beFifwU08nQdO0Au8P3hxSvIUnoepKfwW

我的问题是:这个问题是关于系统的吗?还是php版本?

还是关于 php 的 md5() 函数?

我在tank auth中提供了一些密码哈希代码:

function PasswordHash($iteration_count_log2, $portable_hashes)
{
    $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
        $iteration_count_log2 = 8;
    $this->iteration_count_log2 = $iteration_count_log2;
    $this->portable_hashes = $portable_hashes;
    $this->random_state = microtime();
    if (function_exists('getmypid'))
        $this->random_state .= getmypid();
}
function get_random_bytes($count)
{
    $output = '';
    if (is_readable('/dev/urandom') &&
        ($fh = @fopen('/dev/urandom', 'rb'))) {
        $output = fread($fh, $count);
        fclose($fh);
    }
    if (strlen($output) < $count) {
        $output = '';
        for ($i = 0; $i < $count; $i += 16) {
            $this->random_state =
                md5(microtime() . $this->random_state);
            $output .=
                pack('H*', md5($this->random_state));
        }
        $output = substr($output, 0, $count);
    }
    return $output;
}
function encode64($input, $count)
{
    $output = '';
    $i = 0;
    do {
        $value = ord($input[$i++]);
        $output .= $this->itoa64[$value & 0x3f];
        if ($i < $count)
            $value |= ord($input[$i]) << 8;
        $output .= $this->itoa64[($value >> 6) & 0x3f];
        if ($i++ >= $count)
            break;
        if ($i < $count)
            $value |= ord($input[$i]) << 16;
        $output .= $this->itoa64[($value >> 12) & 0x3f];
        if ($i++ >= $count)
            break;
        $output .= $this->itoa64[($value >> 18) & 0x3f];
    } while ($i < $count);
    return $output;
}
    function HashPassword($password)
{
    $random = '';
    if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
        $random = $this->get_random_bytes(16);
        $hash =
            crypt($password, $this->gensalt_blowfish($random));
        if (strlen($hash) == 60)
            return $hash;
    }
    if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) {
        if (strlen($random) < 3)
            $random = $this->get_random_bytes(3);
        $hash =
            crypt($password, $this->gensalt_extended($random));
        if (strlen($hash) == 20)
            return $hash;
    }
    if (strlen($random) < 6)
        $random = $this->get_random_bytes(6);
    $hash =
        $this->crypt_private($password,
        $this->gensalt_private($random));
    if (strlen($hash) == 34)
        return $hash;
    # Returning '*' on error is safe here, but would _not_ be safe
    # in a crypt(3)-like function used _both_ for generating new
    # hashes and for validating passwords against existing hashes.
    return '*';
}

知道吗?我在谷歌中搜索了这个问题,但得到的信息很少,你能帮我吗?谢谢。。

哦,也许是关于CRYPT_BLOWFISH。Linux 没有CRYPT_BLOWFISH。

我自己得到了解决方案。

问题是关于 php 版本。

CRYPT_BLOWFISH不支持 php 5.2,但 php 5.3 可以。

谢谢大家。

最新更新